I would like my phone to execute certain shell scripts via Tasker if my phone is on the same wifi network as my laptop. My initial idea is to edit the /etc/hosts file, but this wouldn't work since neither device is constrained to be on only one wifi network.

A much more costly idea would be to just ping every possible address on the network from my phone, then attempt to send a command via ssh (say, echo $ANDROID) and listen for the response.

The best way to do this is to just be able to see if a device named "myLaptop" exists on the network.. (or, actually, I could use MAC address too.) but I have no idea if this is possible in bash. Is it?

(I'm also open to implementations in Perl, since I can use SL4A to implement Perl scripts.)

  • Is doing the host lookup on the console required?
    – Dan
    Commented Aug 4, 2011 at 0:00
  • not sure what you mean there. if by console you mean terminal, then yes - the idea is on my phone, Tasker can run a shell (or Perl, or Python, or some other language supported by SL4A) script that queries if my laptop is on the same network; if it is, execute particular tasks within the Tasker environment.
    – strictlyrude27
    Commented Aug 4, 2011 at 0:07
  • Do you want this to work across multiple networks? That is, not just on your home network, but also if both laptop & phone are connected to any random network?
    – David Yaw
    Commented Aug 4, 2011 at 0:27
  • Yes. It's a pretty simple matter if it was on one network, I think..?
    – strictlyrude27
    Commented Aug 4, 2011 at 0:30

4 Answers 4


Dynamic DNS service would work. Get your laptop to update your dynamic domain with it's local ip, and then whenever your phone connects to a new wifi network, resolve that domain, if you get a hit, you're either good or happened to find someone with the same local ip!

Similar to that, you could get your laptop to post it's ip to a server somewhere (web, email, w/e) that you can retrieve from a script on your phone.

Short of setting up a DNS server, I'm not sure there is any means for resolving host names that aren't named in your local configs.

  • I like the idea of posting to a server, and in fact I have a server machine at home I could use for this purpose. It seems a little bit inelegant, but it might be the best option.
    – strictlyrude27
    Commented Aug 4, 2011 at 0:26
  • 3
    if you don't own a server, you can use dropbox.
    – Lie Ryan
    Commented Aug 4, 2011 at 0:30
  • 1
    If you've got ssh running, it should be easy to find a hook for wifi connecting, grep your ip and ssh echo or scp the ip back home. Then all your phone has to do is scp it back.
    – Eric Coutu
    Commented Aug 4, 2011 at 0:32
  • I'll accept for now - I'll toy with all the other ideas though!
    – Dang Khoa
    Commented Aug 6, 2011 at 17:38

If you don't want a server-based solution, your laptop could listen to the network for a specific broadcast packet. A broadcast packet will be rerouted to every device in the same network, but devices that aren't listening to it should ignore it.

  • This sounds like an ideal option! Not sure how to accomplish this in bash, if you could provide an example that would be very helpful; especially the listener side.
    – strictlyrude27
    Commented Aug 4, 2011 at 1:25
  • I'm not sure if you can do this from bash, but it's not difficult from either C or Java.
    – David Yaw
    Commented Aug 4, 2011 at 1:45
  • It's a pretty simple thing in C and/or Java, I agree. But it has to be a shell script. I can only run shell or interpretable scripts (running the script from Tasker on my phone.)
    – strictlyrude27
    Commented Aug 4, 2011 at 6:19
  • If you write it in C, and compile to an executable (like the other shell execs (chmod, chown, etc.)), it can be invoked by a shell script if you drop the exec into a dir in your 1PATH, namely /system/bin`.
    – KevinOrr
    Commented Apr 18, 2013 at 2:51

You can use avahi (wiki) (or a similar piece of Zeroconf software) to discover computers on the network and publish the list for your phone to retreive.

See https://stackoverflow.com/questions/1233204/are-there-any-other-java-libraries-for-bonjour-zeroconf-apart-from-jmdns for Java Zeroconf implementations.


There's an application called Network Discovery (available on F-Droid, may also be on the Android Market) that attempts to identify devices on the network your phone is connected to.

As it's Free Software, you could try to see if you can modify it or use portions of it for your purposes.

Not a "here's an APK" answer, but if you have to write something, it's a good start.

Edit: App is here: http://f-droid.org/repository/browse/?fdfilter=network%20discovery&fdid=info.lamatricexiste.network&fdpage=1

  • It's helpful generally speaking, but it won't suit my needs if I can't get this information into Tasker. That's why I wanted to go the shell script route - Tasker can execute shell scripts and interpreted scripts. I would upvote if I could, but this question got migrated from Stack Overflow and I don't have any rep here yet :/
    – Dang Khoa
    Commented Aug 6, 2011 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .