Easiest way to show my IP address?
After I've booted up, what's the easiest way to obtain and display the IP address that the device is currently using?
I'm using Raspbian, and
ifconfigdoesn't appear to be installed.
Are there any widgets that display this information in LXDE?
I'm realizing that now. I think I got spoiled by Ubuntu's command line hints. I'll check it out when I power it back up.
That's a bash thing, rather than a Ubuntu thing. I think ifconfig is just installed with different permissions.
Yep, I forgot to sudo. ifconfig is installed by default, but it comes up with a command not found error if you don't sudo it. Thanks!
The if family of tools including ifconfig are being deprecated and replaced by the newer ip commands so you can use any one of the following from the command line to determine your IP address:
sudo ip addr show
sudo hostname --ip-address
or if you still want to use ifconfig, and it is not already installed
sudo apt-get install wireless-tools sudo ifconfig -a
@jackweirdy that is the newer tools that are replacing the old if tools. Try man ip for some additional details.
@ppumkin possibly but I don't know I guess you could dump the cache,but that may return multiple hosts leaving you to puzzle out which ip belongs to which host.
You can use this little python script as well.
import socket def get_local_ip_address(target): ipaddr = '' try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect((target, 8000)) ipaddr = s.getsockname() s.close() except: pass return ipaddr print "Raspberry Pi - Local IP Address" print(get_local_ip_address('10.0.1.1')) print(get_local_ip_address('google.com'))
A bit overkill don't you think? Not much point replacing the existing Linux commands that achieve the same.
@Jivings Bit harsh - it's an answer, that works! (I say without testing...) It could be the basis of a widget on a desktop for instance.
As an alternative to finding the DHCP assigned IP address, I've added a reserved IP address in my router/DHCP server. It matches the MAC address of the Raspi and always assigns the same IP address - even after a fresh install of the OS.
With Wheezy now having SSH enabled by default, it means I can login to a freshly installed Raspberry Pi without ever needing to connect a keyboard or monitor.
Apologies for not answering the question directly, but it seemed closely related enough to suggest.
You may be able to check the DHCP status/logs on your DHCP server. Especially if it's on your home network. On all the routers I have owned this has been fairly easy to find.
This is helpful if you are running headless and just want to know the address to ssh to.
@gnibbler +1 for addressing the issue for those running headless. One think to note, identifying which device is the Pi can be tricky since it does not always identify itself over the network, and so, may show up without a name in the attached devices list. This thread http://www.raspberrypi.org/phpBB3/viewtopic.php?f=36&;t=6998 has more on the problem and solution
$ host raspberrypi raspberrypi has address 192.168.1.20 $ host raspberrypi | grep ‘address’ | cut -d’ ‘ -f4 192.168.1.20 $ nslookup 192.168.1.20 Server: 192.168.1.1 Address: 192.168.1.1#53 184.108.40.206.in-addr.arpa name = raspberrypi. $ nslookup 192.168.1.20 | grep ‘=’ | cut -d’ ‘ -f3 raspberrypi
If you want to see your external ip address use this on your command line
curl http://ipecho.net/plain; echo;
You could create a function to make it easier.
Edit your .bashrc and add the following function at the end of the file.
Function to display the external ip address
Calling your function from cli
You may find more interesting ways to obtain your ip address in this link
Shea Silverman and Jacob Bates have recently created a tool called PIP that allows you to obtain the IP of your raspberry pi without even attaching it to a screen, as it installs a script that send your IP address to a server that you can visit with your main PC. It may not be the best option in every situation, but it is a very clever hack.