本文整理汇总了Python中scapy.utils.atol方法的典型用法代码示例。如果您正苦于以下问题:Python utils.atol方法的具体用法?Python utils.atol怎么用?Python utils.atol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy.utils
的用法示例。
在下文中一共展示了utils.atol方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_route
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def make_route(self, host=None, net=None, gw=None, dev=None, metric=1):
from scapy.arch import get_if_addr
if host is not None:
thenet, msk = host, 32
elif net is not None:
thenet, msk = net.split("/")
msk = int(msk)
else:
raise Scapy_Exception("make_route: Incorrect parameters. You should specify a host or a net") # noqa: E501
if gw is None:
gw = "0.0.0.0"
if dev is None:
if gw:
nhop = gw
else:
nhop = thenet
dev, ifaddr, _ = self.route(nhop)
else:
ifaddr = get_if_addr(dev)
return (atol(thenet), itom(msk), gw, dev, ifaddr, metric)
示例2: ifchange
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def ifchange(self, iff, addr):
self.invalidate_cache()
the_addr, the_msk = (addr.split("/") + ["32"])[:2]
the_msk = itom(int(the_msk))
the_rawaddr = atol(the_addr)
the_net = the_rawaddr & the_msk
for i, route in enumerate(self.routes):
net, msk, gw, iface, addr, metric = route
if scapy.consts.WINDOWS:
if iff.guid != iface.guid:
continue
elif iff != iface:
continue
if gw == '0.0.0.0':
self.routes[i] = (the_net, the_msk, gw, iface, the_addr, metric) # noqa: E501
else:
self.routes[i] = (net, msk, gw, iface, the_addr, metric)
conf.netcache.flush()
示例3: parse_options
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def parse_options(self, pool=Net("192.168.1.128/25"), network="192.168.1.0/24", gw="192.168.1.1", # noqa: E501
domain="localnet", renewal_time=60, lease_time=1800):
self.domain = domain
netw, msk = (network.split("/") + ["32"])[:2]
msk = itom(int(msk))
self.netmask = ltoa(msk)
self.network = ltoa(atol(netw) & msk)
self.broadcast = ltoa(atol(self.network) | (0xffffffff & ~msk))
self.gw = gw
if isinstance(pool, six.string_types):
pool = Net(pool)
if isinstance(pool, Iterable):
pool = [k for k in pool if k not in [gw, self.network, self.broadcast]] # noqa: E501
pool.reverse()
if len(pool) == 1:
pool, = pool
self.pool = pool
self.lease_time = lease_time
self.renewal_time = renewal_time
self.leases = {}
示例4: make_route
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def make_route(self, host=None, net=None, gw=None, dev=None):
if host is not None:
thenet,msk = host,32
elif net is not None:
thenet,msk = net.split("/")
msk = int(msk)
else:
raise Scapy_Exception("make_route: Incorrect parameters. You should specify a host or a net")
if gw is None:
gw="0.0.0.0"
if dev is None:
if gw:
nhop = gw
else:
nhop = thenet
dev,ifaddr,x = self.route(nhop)
else:
ifaddr = get_if_addr(dev)
return (atol(thenet), itom(msk), gw, dev, ifaddr)
示例5: ifchange
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def ifchange(self, iff, addr):
self.invalidate_cache()
the_addr,the_msk = (addr.split("/")+["32"])[:2]
the_msk = itom(int(the_msk))
the_rawaddr = atol(the_addr)
the_net = the_rawaddr & the_msk
for i in range(len(self.routes)):
net,msk,gw,iface,addr = self.routes[i]
if iface != iff:
continue
if gw == '0.0.0.0':
self.routes[i] = (the_net,the_msk,gw,iface,the_addr)
else:
self.routes[i] = (net,msk,gw,iface,the_addr)
conf.netcache.flush()
示例6: read_routes
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def read_routes():
ok = 0
routes = []
ip = '(\d+\.\d+\.\d+\.\d+)'
# On Vista and Windows 7 the gateway can be IP or 'On-link'.
# But the exact 'On-link' string depends on the locale, so we allow any text.
gw_pattern = '(.+)'
metric_pattern = "(\d+)"
delim = "\s+" # The columns are separated by whitespace
netstat_line = delim.join([ip, ip, gw_pattern, ip, metric_pattern])
pattern = re.compile(netstat_line)
f=os.popen("netstat -rn")
for l in f.readlines():
match = re.search(pattern,l)
if match:
dest = match.group(1)
mask = match.group(2)
gw = match.group(3)
netif = match.group(4)
metric = match.group(5)
try:
intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
except OSError:
log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
continue
if not intf.has_key("addr"):
break
addr = str(intf["addr"])
addr = addr.split("/")[0]
dest = atol(dest)
mask = atol(mask)
# If the gateway is no IP we assume it's on-link
gw_ipmatch = re.search('\d+\.\d+\.\d+\.\d+', gw)
if gw_ipmatch:
gw = gw_ipmatch.group(0)
else:
gw = netif
routes.append((dest,mask,gw, str(intf["name"]), addr))
f.close()
return routes
示例7: ifadd
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def ifadd(self, iff, addr):
self.invalidate_cache()
the_addr, the_msk = (addr.split("/") + ["32"])[:2]
the_msk = itom(int(the_msk))
the_rawaddr = atol(the_addr)
the_net = the_rawaddr & the_msk
self.routes.append((the_net, the_msk, '0.0.0.0', iff, the_addr, 1))
示例8: isValidMCAddr
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def isValidMCAddr(ip):
"""convert dotted quad string to long and check the first octet"""
FirstOct = atol(ip) >> 24 & 0xFF
return (FirstOct >= 224) and (FirstOct <= 239)
示例9: ifadd
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def ifadd(self, iff, addr):
self.invalidate_cache()
the_addr,the_msk = (addr.split("/")+["32"])[:2]
the_msk = itom(int(the_msk))
the_rawaddr = atol(the_addr)
the_net = the_rawaddr & the_msk
self.routes.append((the_net,the_msk,'0.0.0.0',iff,the_addr))
示例10: route
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def route(self,dest,verbose=None):
if type(dest) is list and dest:
dest = dest[0]
if dest in self.cache:
return self.cache[dest]
if verbose is None:
verbose=conf.verb
# Transform "192.168.*.1-5" to one IP of the set
dst = dest.split("/")[0]
dst = dst.replace("*","0")
while True:
l = dst.find("-")
if l < 0:
break
m = (dst[l:]+".").find(".")
dst = dst[:l]+dst[l+m:]
dst = atol(dst)
pathes=[]
for d,m,gw,i,a in self.routes:
aa = atol(a)
#Commented out after issue with virtual network with local address 0.0.0.0
#if aa == dst:
# pathes.append((0xffffffff,(LOOPBACK_NAME,a,"0.0.0.0")))
if (dst & m) == (d & m):
pathes.append((m,(i,a,gw)))
if not pathes:
if verbose:
warning("No route found (no default route?)")
return LOOPBACK_NAME,"0.0.0.0","0.0.0.0" #XXX linux specific!
# Choose the more specific route (greatest netmask).
# XXX: we don't care about metrics
pathes.sort()
ret = pathes[-1][1]
self.cache[dest] = ret
return ret
示例11: get_if_bcast
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def get_if_bcast(self, iff):
for net, msk, gw, iface, addr in self.routes:
if (iff == iface and net != 0):
bcast = atol(addr)|(~msk&0xffffffff); # FIXME: check error in atol()
return ltoa(bcast);
warning("No broadcast address found for iface %s\n" % iff);
示例12: is_valid_mcaddr
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def is_valid_mcaddr(ip):
byte1 = atol(ip) >> 24 & 0xff
return (byte1 & 0xf0) == 0xe0
示例13: fixup
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def fixup(pkt):
"""Fixes up the underlying IP() and Ether() headers."""
assert pkt.haslayer(IGMPv3), \
"This packet is not an IGMPv4 packet; cannot fix it up"
igmp = pkt.getlayer(IGMPv3)
if pkt.haslayer(IP):
ip = pkt.getlayer(IP)
ip.ttl = 1
ip.proto = 2
ip.tos = 0xc0
ip.options = [IPOption_Router_Alert()]
if igmp.type == IGMP_TYPE_MEMBERSHIP_QUERY:
if igmp.gaddr == "0.0.0.0":
ip.dst = "224.0.0.1"
else:
assert IGMPv3.is_valid_mcaddr(igmp.gaddr), \
"IGMP membership query with invalid mcast address"
ip.dst = igmp.gaddr
elif igmp.type == IGMP_TYPE_V2_LEAVE_GROUP and \
IGMPv3.is_valid_mcaddr(igmp.gaddr):
ip.dst = "224.0.0.2"
elif igmp.type in (IGMP_TYPE_V1_MEMBERSHIP_REPORT,
IGMP_TYPE_V2_MEMBERSHIP_REPORT) and \
IGMPv3.is_valid_mcaddr(igmp.gaddr):
ip.dst = igmp.gaddr
# We do not need to fixup the ether layer, it is done by scapy
#
# if pkt.haslayer(Ether):
# eth = pkt.getlayer(Ether)
# ip_long = atol(ip.dst)
# ether.dst = '01:00:5e:%02x:%02x:%02x' % (
# (ip_long >> 16) & 0x7f, (ip_long >> 8) & 0xff,
# ip_long & 0xff )
return pkt
示例14: route
# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import atol [as 别名]
def route(self, dst=None, verbose=conf.verb):
"""Returns the IPv4 routes to a host.
parameters:
- dst: the IPv4 of the destination host
returns: (iface, output_ip, gateway_ip)
- iface: the interface used to connect to the host
- output_ip: the outgoing IP that will be used
- gateway_ip: the gateway IP that will be used
"""
dst = dst or "0.0.0.0" # Enable route(None) to return default route
if isinstance(dst, bytes):
try:
dst = plain_str(dst)
except UnicodeDecodeError:
raise TypeError("Unknown IP address input (bytes)")
if dst in self.cache:
return self.cache[dst]
# Transform "192.168.*.1-5" to one IP of the set
_dst = dst.split("/")[0].replace("*", "0")
while True:
idx = _dst.find("-")
if idx < 0:
break
m = (_dst[idx:] + ".").find(".")
_dst = _dst[:idx] + _dst[idx + m:]
atol_dst = atol(_dst)
paths = []
for d, m, gw, i, a, me in self.routes:
if not a: # some interfaces may not currently be connected
continue
aa = atol(a)
if aa == atol_dst:
paths.append(
(0xffffffff, 1, (conf.loopback_name, a, "0.0.0.0")) # noqa: E501
)
if (atol_dst & m) == (d & m):
paths.append((m, me, (i, a, gw)))
if not paths:
if verbose:
warning("No route found (no default route?)")
return conf.loopback_name, "0.0.0.0", "0.0.0.0"
# Choose the more specific route
# Sort by greatest netmask and use metrics as a tie-breaker
paths.sort(key=lambda x: (-x[0], x[1]))
# Return interface
ret = paths[0][2]
self.cache[dst] = ret
return ret