Re: Windows getting local ip address

2006-03-23 Thread Arne Ludwig
That man is a genius: >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> s.connect(("gmail.com",80)) >>> print s.getsockname() ('192.168.0.174', 2768) >>> s.close() Should work on Windows as well. -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows getting local ip address

2006-03-23 Thread Erno Kuusela
The traditional right way (tm) to do this is to call getsockname() on the (a?) socket that's connected to the guy you want to tell your address to. This picks the right address in case you have several. If you don't have a socket handy, you can make a connectionless UDP socket and connect() it to a

Re: Windows getting local ip address

2006-03-22 Thread Arne Ludwig
The second solution can give really weird results though, e.g. on my Linux system I get: >>> gethostbyaddr(gethostname()) ('linux.site', ['linux'], ['127.0.0.2']) A more flexible but potentially unportable way would be: >>> import socket >>> import fcntl >>> import struct >>> >>> def get_ip_addr

Re: Windows getting local ip address

2006-03-22 Thread utabintarbo
You can do essentially the same thing substituting "ipconfig" for ifconfig. Though I am sure there are better ways -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows getting local ip address

2006-03-22 Thread Fredrik Lundh
"SolaFide" wrote: > On Linux, it is a simple matter to get the local ip address with > system.os("ifconfig >> /tmp/ip"); ip=open("/tmp/ip").readlines(), etc. ip = os.popen("ifconfig").readlines() is a bit more convenient. > How can I do this with Windows? the command is called "ipconfig" i

Windows getting local ip address

2006-03-22 Thread SolaFide
On Linux, it is a simple matter to get the local ip address with system.os("ifconfig >> /tmp/ip"); ip=open("/tmp/ip").readlines(), etc. How can I do this with Windows? -- http://mail.python.org/mailman/listinfo/python-list