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
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
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
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
"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
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