displayhost.blogg.se

Python mac address generator function
Python mac address generator function




python mac address generator function
  1. #Python mac address generator function code#
  2. #Python mac address generator function windows#

for lib in ( 'uuid', 'c' ): try : lib = ctypes. try : import ctypes.util # The uuid_generate_* routines are provided by # libuuid on at least Linux and FreeBSD and by # libc on MacOS X. return _ipconfig ( _MACsep, MAC ) _all_ips = ( _hostname_ips, _ipconfig_ips ) _all_macs = ( _windll_macs, _netbios_macs, _ipconfig_macs ) else : # *nix _uuid_generate_time = None # If ctypes is available, use it to find routines for # UUID generation (making this module thread-UNsafe!) # Thanks to Thomas Heller for ctypes and for his help # with its use here. return _ipconfig ( 'IP', IP ) _MACsep = '-' def _ipconfig_macs (): # get MAC addresses from ipconfig. append ( Class ( t )) except ( Inde圎rror, TypeError, ValueError ): pass return m def _ipconfig_ips (): # get IP addresses from ipconfig. popen ( c + ' /all' ): if tag in t : try : t = t.

python mac address generator function

decode ( 'mbcs' ),) except ( ImportError, AttributeError ): t = () _dirs = t + ( r'c:\windows\system32', r'c:\winnt\system32', '' ) m, c =, _which ( 'ipconfig.exe', _dirs ) if c : for t in os. create_string_buffer ( 300 ) f ( b, 300 ) t = ( b. global _dirs if _dirs is None : try : # check system directory first f = ctypes. ) def _ipconfig ( tag, Class ): # get IP or MAC addresses from ipconfig /all. adapter_address )) except ( ImportError, AttributeError ): pass _dirs = None # ('c:\.'. ADAPTER_STATUS () if Netbios ( ncb ) = 0 : s. try : import netbios from win32wnet import Netbios ncb = netbios.

python mac address generator function

''' import os import socket import struct import sys try : import ctypes except ImportError : ctypes = None _version_ = '16.07.07' # '10.4.22' _all_ = ( 'getIPs', 'IP', 'isIP', 'getMACs', 'MAC', 'isMAC' ) if sys. This module does not support Python 2.3 and older and has not been tested on platforms other than the ones listed above.

#Python mac address generator function windows#

Tested on CentOS 4 (Intel), MacOS X 10.4.11 Tiger (Intel), MacOS X 10.3.9 Panther (PowerPC), RedHat 3 (Opteron), Solaris 10 (Opteron), Windows XP SP2 and SP3 and Windows Server 2003 R2 with 32-bit Python 2.4, 2.5, 2.6, 3.0 and/or 3.1, on CentOS 4 and 5 (Intel) with 64-bit Python 2.4 and 2.6, on MacOS X 10.11.5 with 64-bit Python 2.7.10 and 3.5.1 and on iOS 9.3.2 with 64-bit Pythonista 2.1 (on iPad).

#Python mac address generator function code#

The core code is copied from standard Python 2.6 and 3.1 module Lib/uuid.py and then modified to: - use immutable classes IP and MAC like UUID, - handle any number of IP and MAC addresses, - collect IP and MAC addresses from several additional sources, - locate external programs only once, - use env and grep with ifconfig on *nixes, - support Python versions 2.4 thru 3.5, both 32- and 64-bit. Use python ipmac.py -debug to include debug output. For both, see module ipaddress (Python 3 only) at Run python ipmac.py to see examples and the test results. The IPv6 format is not supported, only IPv4. The return value is an IP respectively MAC instance if the given address is valid. Functions isIP and isMAC can be used to check an address. Both functions provide an optional argument to exclude specific IP or MAC instances. Functions getIPs and getMACs collect the available IP respectively MAC addresses from the underlying system. The IP class provides properties to check whether the address is link-local, loopback, multicast, a network address or network mask, private (non- routable), TEST-NET, THIS-HOST or THIS-NET. Instances of IP and MAC classes are immutable. Class IP and MAC represent an IP respectively a MAC address. # coding: utf-8 '''This module provides 2 classes and 4 functions to, obtain, check and convert IP and MAC addresses.






Python mac address generator function