jives11
Posts: 6
Joined: Fri Jul 20, 2012 7:49 am

headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 8:03 am

Hi, enjoying my pi, which I run headless and ssh in, running tightvnc when I need the GUI.

Figuring out the IP address is easy at home , I can look at my routers home page and see the pi.

I'd like to take the pi into work, where I have no means of telling what hostname or IP address the headless pi is given by dhcp.

It occured to me that there might be some cool ways of the pi communicating with me on boot :

1) mail: I guess it could smtp me the IP address in the bootup. I'd need to hard code the relay server but it could work when at work ?

2) Sound : I've not looked into this but wonder if the Pi could announce its IP address via the audio out. Perhaps there is a speech synth that could tell me the IP address during boot. This would be very cool ("Hello Dave, my name is pi and my IP address is ........")

3) LED's :) My morse code is non-existent but perhaps the LED's could flash out the IP address

of course I could just plug in a Composite video or HDMI monitor, but that would be far too easy :)

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 8:58 am

I hope you have an understanding boss I know I would probably get the sack if I ran unapproved equipment on the local network.
To figure out your IP address you only need to do this with a customised script one that runs on boot up or executed blindly with an attached keyboard.
This information would then write a text file to attach USB flash drive which you can open with your PC.

Richard S.

jives11
Posts: 6
Joined: Fri Jul 20, 2012 7:49 am

Re: headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 9:10 am

Thanks , writing to the usb is another option.

I'm lucky, no real problem with attaching non-windows devices to my work network, or at least non-windows ones . Half my colleagues bring in their own personal mac books rather than use the provided ones. I once did a demo using a wii

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 9:31 am

There are standard protocols for doing this sort of thing, but you could roll your own.

Have a Python program start at boot and sit waiting for a UDP packet on a certain port. When it receives a packet it sends back a packet to the port number given in the received packet. It doesn't matter what is in the sent packet, but it might be the hostname or something.

The remote machine sends a broadcast packet to the right port, and receives the replies from all the available RaspPis. The source addresses of those packets will be the IP addresses of the RaspPis.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 10:03 am

There are other ways to determine the PI's IP address although they may provide controversial to corporate networks.
Every time a machine connects to a network ARP packets are transmitted which contain the IP address and the MAC address of the machine in question.
There is a program called ARP Monitor http://binaryplant.com/ it sniffs out these packets unfortunately it requires WinPcap drivers.
Another alternative is to use a network ping scan tool, if you machine has an IP address of 192.168.1.100 then you only need to ping the last digits of the IP address 0-255 i.e. 192.168.1.0 to 192.168.1.255.
After pinging the entire network quickly open a DOS Prompt (cmd.exe) and enter the following command: arp -a this should list all active machines on the network with their assigned IP and MAC addresses hopefully you should be able to find your PI.
(To find the MAC address of the PI use: ifconfig eth0)

Richard S.

zardoz99
Posts: 175
Joined: Fri Jan 13, 2012 2:25 pm
Location: Somewhere in Canada.

Re: headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 10:17 am

You could always try using a linux dynamic DNS client to register the current address with an external server, and then always use the DNS name to reference it.

As I run my own DNS servers, I have this automated for most of my DHCP equipment, including the Raspis. However, there are free services available on the internet for just this purpose. Google for "linux dynamic dns client" and see what pops.

Z.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: headless with DHCP- how to figure out the IP address ?

Fri Jul 20, 2012 4:44 pm

Program called Fing can do a network scan and tell you which IP address belongs to which device.
Fing is available on Linux and Android.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

jives11
Posts: 6
Joined: Fri Jul 20, 2012 7:49 am

Re: headless with DHCP- how to figure out the IP address ?

Sat Jul 21, 2012 11:57 am

Thanks everyone. In the end I went with the text to speech approach.

Was very easy just modified /etc/rc.local thus:

if hostname -I > /etc/hostip; then
_IP=`cat /etc/hostip`
[ -z "$_IP" ] || echo "My network IP address is $_IP"
echo "Daisey, daisey, give me your answer do ..." > /tmp/shoutout.tmp
echo "Hello Dave, my IP address is " >> /tmp/shoutout.tmp
echo $_IP >> /tmp/shoutout.tmp
cat /tmp/shoutout.tmp |/usr/bin/festival --tts

fi


the only problem is the known one of getting a half second burst of loud white noise through the audio jack before the the sound. tried an apt-get upgrade and reboot but still having the issue. I wonder if there is a way to mute the volume for a moment first

recantha
Posts: 209
Joined: Mon Jun 25, 2012 10:41 am

Re: headless with DHCP- how to figure out the IP address ?

Wed Jul 25, 2012 9:13 pm

Just published a new blog post bringing together everything I've found about this idea.

http://raspberrypipod.blogspot.co.uk/20 ... my-ip.html

I've got it so that the Pi vocally tells me it's IP address. During start-up, however, the IP address over wifi takes a while to be acquired, so my scripts take this into account.
My Raspberry Pi blog with all my latest projects and links to articles
http://raspberrypipod.blogspot.com. +++ Current project: PiPodTricorder - lots of sensors, lots of mini-displays, breadboarding, bit of programming.

jives11
Posts: 6
Joined: Fri Jul 20, 2012 7:49 am

Re: headless with DHCP- how to figure out the IP address ?

Wed Jul 25, 2012 9:22 pm

Hi recantha,


Do you have the problem where you get a half second burst of static through the 3.5mm audio jack every time before the sound i.e just before festival speaks your message ?

Twinkletoes
Posts: 210
Joined: Fri May 25, 2012 9:44 pm

Re: headless with DHCP- how to figure out the IP address ?

Wed Jul 25, 2012 9:56 pm

Best solution I know is Bonjour otherwise known as Zeroconf. It's a multicast distributed DNS design. I've used it on a few projects now. It even works when there's no DHCP server.

recantha
Posts: 209
Joined: Mon Jun 25, 2012 10:41 am

Re: headless with DHCP- how to figure out the IP address ?

Thu Jul 26, 2012 5:38 am

@jives11
No, I don't get that problem, which was unexpected.
I'm running the very latest Raspian, with everything updated.
There's a bit of minor... popping, I suppose... in the audio, but apart from that no problems.

Oh, I'm also running Hexxeh's firmware updater, if that makes any difference.
My Raspberry Pi blog with all my latest projects and links to articles
http://raspberrypipod.blogspot.com. +++ Current project: PiPodTricorder - lots of sensors, lots of mini-displays, breadboarding, bit of programming.

xpired
Posts: 1
Joined: Wed Mar 06, 2013 7:59 pm

Re: headless with DHCP- how to figure out the IP address ?

Wed Mar 06, 2013 8:01 pm

I have a script that post the IP address to my online webserver with curl.
The webserver stores it, and send an e-mail to me.
I had a SMS service, but it cost to much when I reboot my RPi often.

Bright Sparks NZ
Posts: 20
Joined: Fri Dec 21, 2012 8:11 pm

Re: headless with DHCP- how to figure out the IP address ?

Thu Mar 07, 2013 9:27 am

Try ifconfig ?
~ Andrew

mnatives
Posts: 1
Joined: Thu Mar 07, 2013 9:32 am
Contact: Website

Re: headless with DHCP- how to figure out the IP address ?

Thu Mar 07, 2013 9:45 am

i have a some thing problem of IP When we going SMS Gateway Service.
so Please help me?.

pjc123
Posts: 913
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: headless with DHCP- how to figure out the IP address ?

Fri Mar 08, 2013 12:42 pm

I use "nmap" from my Win 7 desktop and "fing" from my Android smartphone to determine my headless pi's address so i can connect. If applicable to your situation, you could also switch to a static address on the pi.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/

nac
Posts: 2
Joined: Wed Apr 10, 2013 9:16 pm

Re: headless with DHCP- how to figure out the IP address ?

Sat Jan 18, 2014 4:04 pm

I found the output a bit garbled, so I used sed to introduce some spaces and the word "dot" instead of . I found the result more intelligible. In summary:

$sudo apt-get install festival

then, in /etc/rc.local add these four lines:

# 192.168.7.20 becomes "1 9 2 dot 1 6 8 dot 7 dot 2 0"
MY_IP=`hostname -I | sed -e 's/\./ dot /g' -e 's/[0123456789]/ & /g'`
# Say it.
echo "Hello This is raspberry pi and my I P address is $MY_IP" | /usr/bin/festival --tts



regards,

Neal.

paulv
Posts: 558
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: headless with DHCP- how to figure out the IP address ?

Sat Apr 09, 2016 8:32 am

Great trick!
I get more then 1 IP address (using wlan), so I use this just after the hostname -I to get only the eth0 IP address.

Code: Select all

 | mawk '{ print ($1)}' | sed ... 
I suggest to use "dot." Instead of just "dot".
The period after dot adds a pause so the text is more easy to follow.
You can also add a few .... as a pause just before the $MY_IP

Return to “Beginners”