ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

netmask is returning None #60

Open farp80 opened 3 years ago

farp80 commented 3 years ago

I am trying to get IP/subnet using the code in this repo, but I am getting NOne as result in the Netmask, even though I can confirm the subnet mask through cmd. this is the response:

{
  'Ethernet adapter Ethernet 2': {
    'inet': None,
    'inet4': [

    ],
    'ether': 'e8:6a:64:3f:e5:c3',
    'inet6': [

    ],
    'netmask': None,
    'device': 'ethernet adapter ethernet 2'
  },
  'Ethernet adapter VirtualBox Host-Only Network': {
    'inet': '192.168.56.1',
    'inet4': [
      '192.168.56.1'
    ],
    'ether': '0a:00:27:00:00:15',
    'inet6': [

    ],
    'netmask': None,
    'device': 'ethernet adapter virtualbox host-only network',
    'hostname': 'fidel-desktop'
  },
  'Ethernet adapter Ethernet 3': {
    'inet': '192.168.1.15',
    'inet4': [
      '192.168.1.15'
    ],
    'ether': '94:05:bb:12:19:db',
    'inet6': [

    ],
    'netmask': None,
    'device': 'ethernet adapter ethernet 3',
    'hostname': 'fidel-desktop'
  },
  'Wireless LAN adapter Local Area Connection* 3': {
    'inet': None,
    'inet4': [

    ],
    'ether': '18:56:80:2e:1d:0b',
    'inet6': [

    ],
    'netmask': None,
    'device': 'wireless lan adapter local area connection* 3'
  },
  'Wireless LAN adapter Local Area Connection* 4': {
    'inet': None,
    'inet4': [

    ],
    'ether': '1a:56:80:2e:1d:0a',
    'inet6': [

    ],
    'netmask': None,
    'device': 'wireless lan adapter local area connection* 4'
  },
  'Ethernet adapter Bluetooth Network Connection 2': {
    'inet': None,
    'inet4': [

    ],
    'ether': '18:56:80:2e:1d:0e',
    'inet6': [

    ],
    'netmask': None,
    'device': 'ethernet adapter bluetooth network connection 2'
  },
  'Wireless LAN adapter Wi-Fi 2': {
    'inet': None,
    'inet4': [

    ],
    'ether': '18:56:80:2e:1d:0a',
    'inet6': [

    ],
    'netmask': None,
    'device': 'wireless lan adapter wi-fi 2'
  }
}
benjaoming commented 3 years ago

Hi @farp80

Could you format your code in a readable way and perhaps provide details such as your operating system and the outputs of the "cmd" that you are talking about?

farp80 commented 3 years ago

ifcfg.txt Hi. This is what I did:

  1. I imported ifcfg and then access its method to get my interface's settings. [NOTE]: I am using Windows 10. I did the ipconfig/all.

Attached is the file (formatted) with the ifcfg's response.

I think you can verify my doubts if you run it in a Windows environment.

Thanks.

jonboiser commented 3 years ago

I edited the original post. The formatting was off because the whole output was wrapped in a single backtick.

farp80 commented 3 years ago

@jonboiser : thanks. I just clicked the insert code icon.

benjaoming commented 3 years ago

@farp80 for someone to work on the issue, they will likely need the output of when you run the ipconfig /all command. Could you contribute that?

arpitsaigal commented 1 year ago

Could this be because there is no pattern for 'Subnet Mask' in the get_patterns() method in the Windows parser?

@classmethod
def get_patterns(cls):
    return [
        r"^(?P<device>\w.+):",
        r"^   Physical Address. . . . . . . . . : (?P<ether>[ABCDEFabcdef\d-]+)",
        r"^   IPv4 Address. . . . . . . . . . . : (?P<inet4>[^\s\(]+)",
        r"^   IPv6 Address. . . . . . . . . . . : (?P<inet6>[ABCDEFabcdef\d\:\%]+)",
        r"^\s+Default Gateway . . . . . . . . . : (?P<default_gateway>[^\s\(]+)",
    ]