python 获取本机计算机名和IP地址

1.

>>>import socket

>>>hostname = socket.gethostname()
'OOooo-PC'

>>>ip = socket.gethostbyname(hostname)
>>>print ip
'172.8.4.16'

>>> ipList = socket.gethostbyname_ex(hostname)
>>> ipList
('OOooo-PC', [], ['172.8.4.16', '10.5.48.93'])

2.
>>> name = socket.getfqdn(socket.gethostname())
>>> name
'OOooo-PC'


你可能感兴趣的:(Python)