lazarus78
Posts: 236
Joined: Thu Jul 25, 2013 5:16 pm

Command(s) to get just your IP?

Tue Oct 29, 2013 6:45 pm

I need a command or commands to return just my local IP, nothing else. Its rather amazing how hard it is to do this, nothing i found in my searches worked or returned more then just the address.

karlkiste
Posts: 189
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Command(s) to get just your IP?

Tue Oct 29, 2013 6:59 pm

Look in the file /etc/rc.local of raspbian os.

User avatar
DougieLawson
Posts: 36528
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Command(s) to get just your IP?

Tue Oct 29, 2013 7:03 pm

How about:
  1. `ifconfig wlan0 | grep 'inet addr'
  2. `ip -4 addr` | awk '{print $4}'
  3. host `hostname` # the backticks are important
pick your poison.

You may need to run the output from those commands through grep, sed or awk to strip out just the address. I'll leave that as an exercise. It's a good skill to learn awk.
Last edited by DougieLawson on Tue Oct 29, 2013 7:08 pm, edited 2 times in total.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

lazarus78
Posts: 236
Joined: Thu Jul 25, 2013 5:16 pm

Re: Command(s) to get just your IP?

Tue Oct 29, 2013 7:03 pm

Wow... that simple...

Code: Select all

hostname -I
DougieLawson wrote:How about:
  1. `ifconfig wlan0 | grep 'inet addr'
  2. `ip -4 addr`
  3. host `hostname` # the backticks are important
pick your poison.
1 and 3 don't work. 2 doesn't return just the IP as I needed.

User avatar
DougieLawson
Posts: 36528
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Command(s) to get just your IP?

Tue Oct 29, 2013 7:11 pm

lazarus78 wrote:Wow... that simple...

Code: Select all

hostname -I
Beware `hostname -i` or `hostname -I` doesn't work cleanly on my system

Code: Select all

[email protected] ~ $ hostname -i
2001:xxxx:xxxx:2e00:821f:2ff:fe68:c6af 10.1.1.7
[email protected] ~ $ hostname -I
10.1.1.7 2001:xxxx:xxxx:2e00:821f:2ff:fe68:c6af
[email protected] ~ $
because my RPi is running both IPv4 & IPv6.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

lazarus78
Posts: 236
Joined: Thu Jul 25, 2013 5:16 pm

Re: Command(s) to get just your IP?

Tue Oct 29, 2013 7:49 pm

Makes sense. The systems I am using it for are all running IPv4 only apparently. (CentOS, Debian, and Raspbian)

thanks for the warning though.

Return to “Beginners”