获得第几块网卡的ip地址:

如何在其他文件夹中导入模块

import sys
sys.path.append('/search/chen/tool')#你的代码存放的目录
from  Get_Ip import get_ip_address_num

获取网卡的IP地址和后缀:

import socket
import fcntl
import struct
def get_ip_address(self,ifname):
        # ifname = 'eth0'
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        return socket.inet_ntoa(fcntl.ioctl(
            s.fileno(),
            0x8915,# SIOCGIFADDR
            struct.pack('256s', ifname[:15])
        )[20:24])
def get_ip_assress_num():
    ipp = get_ip_address("eth0")
    ip_num = ipp.split('.')[3]
    return ip_num

 

相关文章:

  • 2023-01-06
  • 1970-01-01
  • 2021-10-20
  • 2021-12-29
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2022-02-12
相关资源
相似解决方案