This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: hot to get IP from shell -> C solution


electa wrote:

/* little utility to get the IP address of the machine
- prints the IP address in triple-dotted form xxx.yyy.zzz.www,
or nothing if can't get it.
- this code is a fragment from EpidEm code.
*/

The Python one is easier... ;-)


#!/usr/bin/env python
# Print IP address of the machine, or nothing.
import socket
try:
    print socket.gethostbyname( socket.gethostname() )
except:
    pass

Perl's probably just as easy.

--
Chris Herborth                                     chrish@cryptocard.com
Documentation Overlord, CRYPTOCard Corp.      http://www.cryptocard.com/
Never send a monster to do the work of an evil scientist.
Postatem obscuri lateris nescitis.


-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]