Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: How to find machine's IP address (localhost)?< Next Oldest | Next Newest >
rlr0304 Offline





Group: Members
Posts: 8
Joined: Jan. 2007
Posted: Jan. 16 2007,02:09 QUOTE

Within a bash script, I'm trying to obtain the machine's local IP address.  My couple stabs at it hasn't work, and I haven't been able to find any working examples on the web.  I found one example that used "host" and another that uses "ipaddr", neither of which seems to work on DSL.

Does anyone know how to do this, or can otherwise point me in the right direction?

TIA,

Richard
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 16 2007,04:03 QUOTE

/sbin/ifconfig

--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
rlr0304 Offline





Group: Members
Posts: 8
Joined: Jan. 2007
Posted: Jan. 16 2007,05:56 QUOTE

Thank for the reply, but how do I get the output of ifconfig into a variable so I can proceed to extract the ip address?

Richard
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 16 2007,06:23 QUOTE

I'd suggest for you to browse some scripting guide, or the like.

ie you can typically use
MY_VAR=`ifconfig`
or
MY_VAR=$(ifconfig)
Back to top
Profile PM 
roberts Offline





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Jan. 16 2007,13:21 QUOTE

In bash, just pipe together some commands.
If you only have one net interface active something like:

#!/bin/bash
IP=`ifconfig | grep addr: | grep -v 127.0.0.1 | cut -f2 -d: | awk '{print $1}'`
echo "$IP"
Back to top
Profile PM WEB 
5 replies since Jan. 16 2007,02:09 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: How to find machine's IP address (localhost)?

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code