Python獲取Linux系統(tǒng)下的本機(jī)IP地址代碼分享
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 14:31:19
Python獲取Linux系統(tǒng)下的本機(jī)IP地址代碼分享
Python獲取Linux系統(tǒng)下的本機(jī)IP地址代碼分享:有時(shí)候使用到獲取本機(jī)IP,就采用以下方式進(jìn)行。 代碼如下: #!/usr/bin/python import socket import struct import fcntl def getip(ethname): s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) re
導(dǎo)讀Python獲取Linux系統(tǒng)下的本機(jī)IP地址代碼分享:有時(shí)候使用到獲取本機(jī)IP,就采用以下方式進(jìn)行。 代碼如下: #!/usr/bin/python import socket import struct import fcntl def getip(ethname): s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) re
有時(shí)候使用到獲取本機(jī)IP,就采用以下方式進(jìn)行。
代碼如下:
#!/usr/bin/python
import socket
import struct
import fcntl
def getip(ethname):
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0X8915, struct.pack(‘256s', ethname[:15]))[20:24])
if __name__=='__main__':
print getip('eth0')
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Python獲取Linux系統(tǒng)下的本機(jī)IP地址代碼分享
Python獲取Linux系統(tǒng)下的本機(jī)IP地址代碼分享:有時(shí)候使用到獲取本機(jī)IP,就采用以下方式進(jìn)行。 代碼如下: #!/usr/bin/python import socket import struct import fcntl def getip(ethname): s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) re