-2

I am trying to scan my local area network information with python. Is there any way to get Network Address with subnet mask information to python?

I want to get the Network Address (local network) and subnet mask information in the variables But when I searched on google, seems like there is no relevant information Thank you!!

Jay Chung
  • 13
  • 3
  • The `ipaddress` module has functions for this. – Barmar Nov 09 '22 at 20:56
  • you could search in Stackoverflow ;-) https://stackoverflow.com/questions/3837069/how-to-get-network-interface-card-names-in-python – Vafa Nov 09 '22 at 21:01

1 Answers1

0

I think this will be helpful to get local network information in your case this might be os dependent.

import netifaces
netifaces.interfaces()

#>>['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']

netifaces.ifaddresses('lo0')

#>>{18: [{'addr': ''}], 2: [{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}], 30: [{'peer': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'addr': '::1'}, {'peer': '', 'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::1%lo0'}]}=['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']