[olug] Unix Tip: GET YOUR IP-ADDRESS, Omaha Perl Mongers

Don Kauffman dkauffman at tconl.com
Sat Mar 22 20:11:44 UTC 2003


  Umm Jeff,

I did what you suggested and got this

 python -c "import socket; print socket.gethostbyname(socket.gethostname())"
10.90.0.0

I did what the tip suggested and got this.

/sbin/ifconfig | grep "inet addr" |  grep -v "127.0.0.1" | awk '{print 
$2;}' |  awk -F':' '{print $2;}'
10.90.2.237

I know why --  it hearkens back to something I had  questions on but 
never got a satisfactory answer about. I'd still like an answer because 
I don't think I've got the system set up correctly. What it amounts to 
is that I don't know how to get the hostname to pull an IP from dhcp 
when the system is starting up. The hostname seems to need a dedicated IP.

Don K.

Jeff Hinrichs wrote:

>>Unix Guru Universe said:
>>    
>>
>>>Type this simple command at the unix-prompt
>>>ifconfig | grep "inet addr" |  grep -v "127.0.0.1" | awk '{print $2;}' |
>>>      
>>>
>awk -F':' '{print $2;}'
>  
>
>>David Walker wrote:
>>    
>>
>>>If a user wished to know their IP address they can simply type ifconfig
>>>      
>>>
>>CM Miller wrote:
>>    
>>
>>>If they have an internet connection, then point browser to
>>>      
>>>
>http://whatismyip.com/
>  
>
>>--- Vincent <vincentr at cox.net> wrote:
>>    
>>
>>>The cookie is yours!
>>>      
>>>
>>Perl Monger solution:
>>
>>ifconfig | perl -ne '/dr:(\S+)/||next;(/127\.0\.0\.1/)||print"$1\n"'
>>
>>Density is good. I'm hoping to win one of the cookies Vincent mentioned
>>in under an hour of labor. -grin-
>>    
>>
>
>Pythonista fashion:
>
> python -c "import socket; print socket.gethostbyname(socket.gethostname())"
>
>+1 not reliant on ifconfig
>+1 works on *nix/win/mac
>+1 no regex's
>Python: "Batteries Included"
>
>Sorry, but the time it took to do this doesn't merit a cookie for me. ; )
>-Jeff
>
>_______________________________________________
>OLUG mailing list
>OLUG at olug.org
>http://lists.olug.org/mailman/listinfo/olug
>
>  
>

-- 
Don Kauffman
Email: mailto:dkauffman at tconl.com
---------------------------------
"There are 10 kinds of people in the world. Those who understand binary and those that don't."





More information about the OLUG mailing list