Questions tagged «nic»

12
如何在Python中从NIC获取IP地址?
在Unix上的Python脚本中发生错误时,将发送一封电子邮件。 如果IP地址是测试服务器192.168.100.37,我被要求在电子邮件的主题行中添加{Testing Environment}。这样,我们就可以拥有一个脚本版本,并可以判断电子邮件是否来自测试服务器上混乱的数据。 但是,当我在Google上搜索时,我会不断找到以下代码: import socket socket.gethostbyname(socket.gethostname()) 但是,这给了我127.0.1.1的IP地址。当我使用ifconfig我得到这个 eth0 Link encap:Ethernet HWaddr 00:1c:c4:2c:c8:3e inet addr:192.168.100.37 Bcast:192.168.100.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:75760697 errors:0 dropped:411180 overruns:0 frame:0 TX packets:23166399 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:59525958247 (59.5 GB) TX bytes:10142130096 (10.1 GB) Interrupt:19 Memory:f0500000-f0520000 lo Link encap:Local …
75 python  unix  networking  nic 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.