gproduct
Posts: 59
Joined: Tue Aug 11, 2015 1:27 pm

Identify the pi by hostname

Fri Jan 06, 2017 6:58 pm

Hello!

I'm working on a project for which I need to know the ip of a pi with a hostname 'test'.

How do I achieve this?

Should I go the long route and ping every device on the network, but how do I know if the hostname is 'test'?

Thanks!

W. H. Heydt
Posts: 12654
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Identify the pi by hostname

Fri Jan 06, 2017 7:05 pm

Current versions of Raspbian broadcast to the LAN. You can connect to one by connecting to "<hostname>.local" providing the source system has the feature enabled. In your case, "test.local".

JumpZero
Posts: 1131
Joined: Thu Mar 28, 2013 7:35 pm
Location: 127.0.0.1

Re: Identify the pi by hostname

Fri Jan 06, 2017 7:06 pm

Hi!
If the pi named test is running stock Raspbian, then the avahi daemon is running on it.
So from another machine on the network you can ping the pi with this command

Code: Select all

ping test.local
Note that this machine must also run avahi/mDNS/Bonjour. This will be the case with a Mac or a recent GNU/Linux but not with Windows (however it seems possible to add this service to Windows as well)
--
Jmp0
Edit: I was 1mn slower than.. W. H. Heydt :oops:
Last edited by JumpZero on Fri Jan 06, 2017 7:09 pm, edited 1 time in total.

gproduct
Posts: 59
Joined: Tue Aug 11, 2015 1:27 pm

Re: Identify the pi by hostname

Fri Jan 06, 2017 7:07 pm

Okay, how do I achieve that with python scripts?

gproduct
Posts: 59
Joined: Tue Aug 11, 2015 1:27 pm

Re: Identify the pi by hostname

Fri Jan 06, 2017 7:10 pm

Yes that works!!!! Thank you very much!
I will transfer the ping to python scripts and ill get what I need.
Again thank you very much!


Return to “General discussion”