blog.fasola.ch


December 3, 2012

easily locating a headless device in a LAN

Category: IT – Matt – 1:21 pm

Assume you’ve got a headless device – e.g. a Raspberry Pi – which you want to connect to via the local network, by http, ssh, or whatever protocol.

By default your device will, once plugged to the lan and powered on, get a dynamically assigned ip address. So your first challenge is to find out it’s actual address in order to connect to it. Sure, you can ask your router which address it had assigned to your device or you just try out – or assign it a static ip for the future.

I ruled those options out, because I want to be able to use it in several different, potentially unknown networks – where I might even have no access to the router.

And the last remaining option – just try through the local subnet – isn’t really a straightforward nor elegant way. So I just quickly hacked together a little ‘service’, that allows any device to register its local address and redirects my web browser by a name tag, provided the local network provides access to the internets….

The only thing needed, is to make the device find its own local ip address and register it by requesting a URL:

http://redirect.fasola.ch/UNIQUENAME/set/LOCAL.IP.HERE

Following that I can be redirected by browsing to http://redirect.fasola.ch/UNIQUENAME  – easy enough.

The first task is easily done by calling a one-liner from the console:

wget -q “redirect.fasola.ch/UNIQUENAME/set/`/sbin/ifconfig eth0 | grep ‘inet addr:’ | cut -d: -f2 | awk ‘{ print $1}’`” >/dev/null 2>&1

To make sure my Raspberry Pi does this by itself after the network’s up, I just registered a little service. Put the following lines into a file called /etc/init.d/register-local-ip

sudo nano /etc/init.d/register-local-ip

(make sure you replace UNIQUENAME with an own name – not too long, but hopefully unique to my picks… 😉

#! /bin/sh
# /etc/init.d/register-local-ip
#
# register with: sudo update-rc.d register-local-ip defaults
# don't forget to change UNIQUENAME for something more meaningful...
#

### BEGIN INIT INFO
# Provides:          register-local-ip
# Required-Start:    $remote_fs $syslog $network $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script register-local-ip "
    wget -q "redirect.fasola.ch/UNIQUENAME/set/`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`" >/dev/null 2>&1
    ;;
  stop)
    echo "Stopping script register-local-ip "
#   optional...
    wget -q "redirect.fasola.ch/UNIQUENAME/del" >/dev/null 2>&1
    ;;
  *)
    echo "Usage: /etc/init.d/register-local-ip {start|stop}"
    exit 1
    ;;
esac

exit 0

make it executable:

sudo chmod +x /etc/init.d/register-local-ip

and register it to start at default runlevels:

sudo update-rc.d register-local-ip defaults

done! no more guessing the local ip. just plug-in your device, wait until it booted, got network access and registered itself. Browse to:

http://redirect.fasola.ch/UNIQUENAME

and you’ll be told the local ip and be redirected automatically after 5 seconds.

If you’d like to use the service, feel free…

 

 

Share

39 Comments »

  1. louis vuitton lanyard

    blog.fasola.ch » easily locating a headless device in a LAN | just what?s moving us?

    Trackback by louis vuitton lanyard — February 10, 2015 @ 2:53 am

  2. Smuk Permanent makeup i Kbh

    blog.fasola.ch » easily locating a headless device in a LAN | just what?s moving us?

    Trackback by Smuk Permanent makeup i Kbh — March 24, 2016 @ 1:30 pm

  3. gta 5 online money generator

    blog.fasola.ch

    Trackback by gta 5 money generator no verification — November 18, 2017 @ 8:14 pm

  4. Vaporizer kaufen

    blog.fasola.ch

    Trackback by Vaporizer — October 18, 2018 @ 3:25 pm

  5. Zahnarzt Zürich

    blog.fasola.ch

    Trackback by styleyoursmile.ch — October 20, 2018 @ 7:39 pm

  6. stripcam4you.com/de/

    blog.fasola.ch

    Trackback by Stripcam4you.com — October 24, 2018 @ 2:19 pm

  7. Silbermünzen

    blog.fasola.ch

    Trackback by Schweizer Silbergeld — November 1, 2018 @ 9:34 pm

  8. Guest friendly hotels Angeles City

    blog.fasola.ch

    Trackback by Guest friendly hotels Angeles City — November 6, 2018 @ 1:00 am

  9. Umzugsfirma Zürich mit kostenlosen Umzugskisten

    blog.fasola.ch

    Trackback by Zügelfirma Zürich — November 18, 2018 @ 3:25 am

  10. Zahnarzt Ungarn

    blog.fasola.ch

    Trackback by dentalreisenungarn.ch — December 3, 2018 @ 7:39 pm

  11. glamira.ch

    blog.fasola.ch

    Trackback by Glamira.ch — December 5, 2018 @ 5:32 am

  12. car rental booking platform

    blog.fasola.ch

    Trackback by mietwagen-check.ch — December 9, 2018 @ 10:43 am

  13. Zahnarzt

    blog.fasola.ch

    Trackback by Zahnarztpraxis — December 16, 2018 @ 1:44 am

  14. webseite erstellen

    blog.fasola.ch

    Trackback by homepage erstellen — December 28, 2018 @ 12:06 am

  15. top4you.ch

    blog.fasola.ch

    Trackback by Top4you.ch — February 24, 2019 @ 8:00 pm

  16. Eurotax

    blog.fasola.ch

    Trackback by Www.autozon.ch — March 5, 2019 @ 12:33 am

  17. Geneva girls

    blog.fasola.ch

    Trackback by Geneva girls — April 15, 2019 @ 12:26 am

  18. Umzugsreinigung

    blog.fasola.ch

    Trackback by Ccs.ag — April 21, 2019 @ 8:56 pm

  19. Grillring

    blog.fasola.ch

    Trackback by Feuerring — May 26, 2019 @ 11:51 am

  20. handyhuellen.ch

    blog.fasola.ch

    Trackback by IPhone Zubehör — May 30, 2019 @ 2:40 pm

  21. maler offerten

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by maler offerten — August 9, 2019 @ 8:01 am

  22. vfxalert.com

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by vfxalert.com — September 5, 2019 @ 8:53 pm

  23. Pozycjonowanie Stron Internetowych Warszawa

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Pozycjonowanie Stron Internetowych Warszawa — September 8, 2019 @ 3:34 am

  24. marketing cina

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by marketing cina — September 13, 2019 @ 3:02 am

  25. Zahnarztpraxis Bern

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Zahnarztpraxis Bern — September 21, 2019 @ 1:09 pm

  26. Hasenchat Schweiz

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Hasenchat Schweiz — September 25, 2019 @ 9:16 am

  27. billardtisch günstig

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by billardtisch günstig — November 4, 2019 @ 12:49 pm

  28. Wohnungsreinigung Zürich

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Wohnungsreinigung Zürich — November 13, 2019 @ 12:13 pm

  29. cosmobutler.com

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by cosmobutler.com — December 16, 2019 @ 12:26 am

  30. diversagroup.ch

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by diversagroup.ch — January 9, 2020 @ 12:39 pm

  31. b-works.io

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by b-works.io — January 15, 2020 @ 4:35 pm

  32. Zahnarzt Luzern

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Zahnarzt Luzern — February 6, 2020 @ 2:54 am

  33. treuhandofferten.ch

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by treuhandofferten.ch — February 21, 2020 @ 4:47 pm

  34. Soins du visage

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Soins du visage — June 20, 2020 @ 2:55 pm

  35. kbclotterywinnerlist.com

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by kbclotterywinnerlist.com — June 25, 2020 @ 3:58 am

  36. Selbstvertrauen stärken

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Selbstvertrauen stärken — July 4, 2020 @ 5:24 pm

  37. Krankenkassen Vergleich

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Krankenkassen Vergleich — August 14, 2020 @ 12:32 pm

  38. Webseite erstellen lassen

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Webseite erstellen lassen — August 20, 2020 @ 2:39 am

  39. Jobs in Schweiz

    blog.fasola.ch » easily locating a headless device in a LAN | just what’s moving us…

    Trackback by Jobs in Schweiz — September 6, 2020 @ 8:07 pm

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> .