def getmacbyip(ip, chainCC=0): """Return MAC address corresponding to a given IP address""" if isinstance(ip,Net): ip = iter(ip).next() ip = inet_ntoa(inet_aton(ip)) tmp = map(ord, inet_aton(ip)) if (tmp[0] & 0xf0) == 0xe0: # mcast @ return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1]&0x7f,tmp[2],tmp[3]) iff,a,gw = conf.route.route(ip) if ( (iff == LOOPBACK_NAME) or (ip == conf.route.get_if_bcast(iff)) ): return "ff:ff:ff:ff:ff:ff" if gw != "0.0.0.0": ip = gw mac = conf.netcache.arp_cache.get(ip) if mac: return mac res = srp1(Ether(dst=ETHER_BROADCAST)/ARP(op="who-has", pdst=ip), type=ETH_P_ARP, iface = iff, timeout=2, verbose=0, chainCC=chainCC, nofilter=1) if res is not None: mac = res.payload.hwsrc conf.netcache.arp_cache[ip] = mac return mac return None
def getmacbyip(ip, chainCC=0): """Return MAC address corresponding to a given IP address""" if isinstance(ip, Net): ip = next(iter(ip)) ip = inet_ntoa(inet_aton(ip or "0.0.0.0")) tmp = [orb(e) for e in inet_aton(ip)] if (tmp[0] & 0xf0) == 0xe0: # mcast @ return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1] & 0x7f, tmp[2], tmp[3]) iff, _, gw = conf.route.route(ip) if ((iff == consts.LOOPBACK_INTERFACE) or (ip == conf.route.get_if_bcast(iff))): # noqa: E501 return "ff:ff:ff:ff:ff:ff" if gw != "0.0.0.0": ip = gw mac = conf.netcache.arp_cache.get(ip) if mac: return mac try: res = srp1(Ether(dst=ETHER_BROADCAST) / ARP(op="who-has", pdst=ip), type=ETH_P_ARP, iface=iff, timeout=2, verbose=0, chainCC=chainCC, nofilter=1) except Exception as ex: warning("getmacbyip failed on %s" % ex) return None if res is not None: mac = res.payload.hwsrc conf.netcache.arp_cache[ip] = mac return mac return None
def do_dec(cls, s, context=None, safe=False): l,s,t = cls.check_type_check_len(s) try: ipaddr_ascii = inet_ntoa(s) except Exception: raise BER_Decoding_Error("IP address could not be decoded") return cls.asn1_object(ipaddr_ascii), t
def do_dec(cls, s, context=None, safe=False): l,s,t = cls.check_type_check_len(s) try: ipaddr_ascii = inet_ntoa(s) except Exception: raise BER_Decoding_Error("IP address could not be decoded", decoded=obj) return cls.asn1_object(ipaddr_ascii), t
def do_dec(cls, s, context=None, safe=False): # type: (bytes, Optional[Any], bool) -> Tuple[ASN1_Object[str], bytes] l, s, t = cls.check_type_check_len(s) try: ipaddr_ascii = inet_ntoa(s) except Exception: raise BER_Decoding_Error("IP address could not be decoded", remaining=s) return cls.asn1_object(ipaddr_ascii), t
def m2i(self, pkt, x): nbr = struct.unpack("!H", x[2:4])[0] - 2 nbr //= 4 x = x[6:] list = [] for i in range(0, nbr): add = x[4 * i:4 * i + 4] list.append(inet_ntoa(add)) return list
def m2i(self, pkt, x): lst = [struct.unpack("!H", x[6:8])[0]] octet = struct.unpack("B", x[8:9])[0] lst.append((octet & 2**7) >> 7) lst.append((octet & 2**6) >> 6) lst.append(struct.unpack("B", x[9:10])[0]) lst.append(struct.unpack("!H", x[10:12])[0]) lst.append(inet_ntoa(x[12:16])) lst.append(struct.unpack("!H", x[16:18])[0]) return lst
def m2i(self, pkt, x): tmp_len = self.length_from(pkt) if tmp_len <= 8: x += b"\x00\x00\x00" elif tmp_len <= 16: x += b"\x00\x00" elif tmp_len <= 24: x += b"\x00" return inet_ntoa(x)
def m2i(self, pkt, x): used = 0 x = x[4:] list = [] while x: # if x[0] == 1: # list.append('Wildcard') # else: # mask=orb(x[8*i+3]) # add=inet_ntoa(x[8*i+4:8*i+8]) mask = orb(x[3]) nbroctets = mask // 8 if mask % 8: nbroctets += 1 add = inet_ntoa(x[4:4 + nbroctets] + b"\x00" * (4 - nbroctets)) list.append((add, mask)) used += 4 + nbroctets x = x[4 + nbroctets:] return list
def parse_logon_group(v): marker, trash1, ip, trash2, port, kernel = struct.unpack( '>9sbIIh4s', v[:24]) ip = struct.pack('!I', ip) return [inet_ntoa(ip), str(port), kernel]