python get host ip socket

[root@CT53-64-BASE tools]# python
Python 2.4.3 (#1, Sep  3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>>> s.connect(("10.224.178.165", 4730))  #这里可以根据你机器可以访问的地址设置ip/域名 和端口号
>>> s.getsockname()
('10.224.178.167', 45889)
>>>s.close()

你可能感兴趣的:(socket,python,gcc)