本文整理汇总了Python中scapy.layers.inet.IP属性的典型用法代码示例。如果您正苦于以下问题:Python inet.IP属性的具体用法?Python inet.IP怎么用?Python inet.IP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类scapy.layers.inet
的用法示例。
在下文中一共展示了inet.IP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: voip_play1
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def voip_play1(s1,list=None,**kargs):
dsp,rd = os.popen2("sox -t .ul - -t ossdsp /dev/dsp")
def play(pkt):
if not pkt:
return
if not pkt.haslayer(UDP):
return
ip=pkt.getlayer(IP)
if s1 in [ip.src, ip.dst]:
dsp.write(pkt.getlayer(Raw).load[12:])
try:
if list is None:
sniff(store=0, prn=play, **kargs)
else:
for p in list:
play(p)
finally:
dsp.close()
rd.close()
示例2: voip_play2
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def voip_play2(s1,**kargs):
dsp,rd = os.popen2("sox -t .ul -c 2 - -t ossdsp /dev/dsp")
def play(pkt,last=[]):
if not pkt:
return
if not pkt.haslayer(UDP):
return
ip=pkt.getlayer(IP)
if s1 in [ip.src, ip.dst]:
if not last:
last.append(pkt)
return
load=last.pop()
x1 = load.load[12:]
# c1.write(load.load[12:])
if load.getlayer(IP).src == ip.src:
x2 = ""
# c2.write("\x00"*len(load.load[12:]))
last.append(pkt)
else:
x2 = pkt.load[:12]
# c2.write(pkt.load[12:])
dsp.write(merge(x1,x2))
sniff(store=0, prn=play, **kargs)
示例3: queso_sig
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def queso_sig(target, dport=80, timeout=3):
p = queso_kdb.get_base()
ret = []
for flags in ["S", "SA", "F", "FA", "SF", "P", "SEC"]:
ans, unans = sr(IP(dst=target)/TCP(dport=dport,flags=flags,seq=RandInt()),
timeout=timeout, verbose=0)
if len(ans) == 0:
rs = "- - - -"
else:
s,r = ans[0]
rs = "%i" % (r.seq != 0)
if not r.ack:
r += " 0"
elif r.ack-s.seq > 666:
rs += " R" % 0
else:
rs += " +%i" % (r.ack-s.seq)
rs += " %X" % r.window
rs += " %x" % r.payload.flags
ret.append(rs)
return ret
示例4: make_reply
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def make_reply(self, req):
mac = req.src
if type(self.pool) is list:
if not self.leases.has_key(mac):
self.leases[mac] = self.pool.pop()
ip = self.leases[mac]
else:
ip = self.pool
repb = req.getlayer(BOOTP).copy()
repb.op="BOOTREPLY"
repb.yiaddr = ip
repb.siaddr = self.gw
repb.ciaddr = self.gw
repb.giaddr = self.gw
del(repb.payload)
rep=Ether(dst=mac)/IP(dst=ip)/UDP(sport=req.dport,dport=req.sport)/repb
return rep
示例5: generate_tcp_packet
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def generate_tcp_packet(ip_src: str = "192.168.64.32", ip_dst: str = "192.168.64.48",
mac_src: str = "56:6D:D9:BC:70:1C", ttl: int = 64,
mac_dst: str = "F4:2B:95:B3:0E:1A", port_src: int = 1337, port_dst: int = 6442,
tcpflags: str = "S", payload: str = ""):
"""
Builds a TCP packet with the values specified by the caller.
:param ip_src: the source IP address of the IP header
:param ip_dst the destination IP address of the IP header
:param mac_src: the source MAC address of the MAC header
:param ttl: the ttl value of the packet
:param mac_dst: the destination MAC address of the MAC header
:param port_src: the source port of the TCP header
:param port_dst: the destination port of the TCP header
:param tcpflags: the TCP flags of the TCP header
:param payload: the payload of the packet
:return: the corresponding TCP packet
"""
ether = Ether(src=mac_src, dst=mac_dst)
ip = IP(src=ip_src, dst=ip_dst, ttl=ttl)
tcp = TCP(sport=port_src, dport=port_dst, flags=tcpflags)
packet = ether / ip / tcp / Raw(load=payload)
return packet
示例6: handle_ack
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def handle_ack(self, pkt, time_sent_request):
"""."""
logger.debug("Handling ACK.")
logger.debug('Modifying obj DHCPCAP, setting server data.')
self.server_mac = pkt[Ether].src
self.server_ip = pkt[IP].src
self.server_port = pkt[UDP].sport
event = DHCP_EVENTS['IP_ACQUIRE']
# FIXME:0 check the fields match the previously offered ones?
# FIXME:50 create a new object also on renewing/rebinding
# or only set_times?
lease = self.handle_offer_ack(pkt, time_sent_request)
lease.set_times(time_sent_request)
if self.lease is not None:
if (self.lease.address != lease.address or
self.lease.subnet_mask != lease.subnet_mask or
self.lease.router != lease.router):
event = DHCP_EVENTS['IP_CHANGE']
else:
event = DHCP_EVENTS['RENEW']
logger.debug('Modifying obj DHCPCAP, setting lease, client ip, event.')
self.lease = lease
self.client_ip = self.lease.address
self.event = event
return event
示例7: __init__
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def __init__(self, ap, name="fakeap"):
threading.Thread.__init__(self)
if len(name) > IFNAMSIZ:
raise Exception("Tun interface name cannot be larger than " + str(IFNAMSIZ))
self.name = name
self.setDaemon(True)
self.ap = ap
# Virtual interface
self.fd = open('/dev/net/tun', 'r+b')
ifr_flags = IFF_TUN | IFF_NO_PI # Tun device without packet information
ifreq = struct.pack('16sH', name, ifr_flags)
fcntl.ioctl(self.fd, TUNSETIFF, ifreq) # Syscall to create interface
# Assign IP and bring interface up
set_ip_address(name, self.ap.ip)
print("Created TUN interface %s at %s. Bind it to your services if needed." % (name, self.ap.ip))
示例8: voip_play1
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def voip_play1(s1,list=None,**kargs):
dsp,rd = os.popen2("sox -t .ul - -t ossdsp /dev/dsp")
def play(pkt):
if not pkt:
return
if not pkt.haslayer(UDP):
return
ip=pkt.getlayer(IP)
if s1 in [ip.src, ip.dst]:
dsp.write(pkt.getlayer(conf.raw_layer).load[12:])
try:
if list is None:
sniff(store=0, prn=play, **kargs)
else:
for p in list:
play(p)
finally:
dsp.close()
rd.close()
示例9: dyndns_add
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def dyndns_add(nameserver, name, rdata, type="A", ttl=10):
"""Send a DNS add message to a nameserver for "name" to have a new "rdata"
dyndns_add(nameserver, name, rdata, type="A", ttl=10) -> result code (0=ok)
example: dyndns_add("ns1.toto.com", "dyn.toto.com", "127.0.0.1")
RFC2136
"""
zone = name[name.find(".")+1:]
r=sr1(IP(dst=nameserver)/UDP()/DNS(opcode=5,
qd=[DNSQR(qname=zone, qtype="SOA")],
ns=[DNSRR(rrname=name, type="A",
ttl=ttl, rdata=rdata)]),
verbose=0, timeout=5)
if r and r.haslayer(DNS):
return r.getlayer(DNS).rcode
else:
return -1
示例10: makeMPCapableSyn
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def makeMPCapableSyn(sourceAddr,dport,dstAddr, sport=None, initTCPSeq=None, \
sendKey=None):
if sport is None: sport = randintb(16)
if initTCPSeq is None: initTCPSeq = randintb(32)
if sendKey is None: sendKey = randintb(32)
#TODO: make more elegant type handling for IPADDR
dstAddr = str(dstAddr)
pkt = (IP(version=4L,src=sourceAddr,dst=dstAddr)/ \
TCP(sport=sport,dport=dport,flags="S",seq=initTCPSeq, \
options=[TCPOption_MP(mptcp=MPTCP_CapableSYN(
checksum_req=1,
snd_key=sendKey))]))
return pkt
示例11: makeJoinSyn
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def makeJoinSyn(sourceAddr,dport,dstAddr, sport=None, initTCPSeq=None, \
mptcpAddrId=None,isBackupFlow=False, \
rcvToken=None,sendNonce=None):
if sport is None: sport = randintb(16)
if sendNonce is None: sendNonce = randintb(32)
if initTCPSeq is None: initTCPSeq = randintb(32)
if rcvToken is None: rcvToken = randintb(32)
if sendNonce is None: sendNonce = randintb(32)
if mptcpAddrId is None: mptcpAddrId = randintb(8)
#TODO: make more elegant type handling for IPADDR
dstAddr = str(dstAddr)
pkt = (IP(version=4L,src=sourceAddr,dst=dstAddr)/ \
TCP(sport=sport,dport=dport,flags="S",seq=initTCPSeq, \
options=[TCPOption_MP(mptcp=MPTCP_JoinSYN(
addr_id=mptcpAddrId,
backup_flow=isBackupFlow,
rcv_token=rcvToken,
snd_nonce=sendNonce,))]))
return pkt
示例12: chexdump
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def chexdump(x, dump=False):
"""Build a per byte hexadecimal representation
Example:
>>> chexdump(IP())
0x45, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00, 0x7c, 0xe7, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01 # noqa: E501
:param x: a Packet
:param dump: print the view if False
:return: a String only if dump=True
"""
x = bytes_encode(x)
s = ", ".join("%#04x" % orb(x) for x in x)
if dump:
return s
else:
print(s)
示例13: dyndns_add
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def dyndns_add(nameserver, name, rdata, type="A", ttl=10):
"""Send a DNS add message to a nameserver for "name" to have a new "rdata"
dyndns_add(nameserver, name, rdata, type="A", ttl=10) -> result code (0=ok)
example: dyndns_add("ns1.toto.com", "dyn.toto.com", "127.0.0.1")
RFC2136
"""
zone = name[name.find(".") + 1:]
r = sr1(IP(dst=nameserver) / UDP() / DNS(opcode=5,
qd=[DNSQR(qname=zone, qtype="SOA")], # noqa: E501
ns=[DNSRR(rrname=name, type="A",
ttl=ttl, rdata=rdata)]),
verbose=0, timeout=5)
if r and r.haslayer(DNS):
return r.getlayer(DNS).rcode
else:
return -1
示例14: dyndns_del
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def dyndns_del(nameserver, name, type="ALL", ttl=10):
"""Send a DNS delete message to a nameserver for "name"
dyndns_del(nameserver, name, type="ANY", ttl=10) -> result code (0=ok)
example: dyndns_del("ns1.toto.com", "dyn.toto.com")
RFC2136
"""
zone = name[name.find(".") + 1:]
r = sr1(IP(dst=nameserver) / UDP() / DNS(opcode=5,
qd=[DNSQR(qname=zone, qtype="SOA")], # noqa: E501
ns=[DNSRR(rrname=name, type=type,
rclass="ANY", ttl=0, rdata="")]), # noqa: E501
verbose=0, timeout=5)
if r and r.haslayer(DNS):
return r.getlayer(DNS).rcode
else:
return -1
示例15: BEGIN
# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import IP [as 别名]
def BEGIN(self):
self.data = [self.origdata[i * self.blocksize:(i + 1) * self.blocksize]
for i in range(len(self.origdata) // self.blocksize + 1)]
self.my_tid = self.sport or RandShort()._fix()
bind_bottom_up(UDP, TFTP, dport=self.my_tid)
self.server_tid = None
self.l3 = IP(dst=self.server) / UDP(sport=self.my_tid, dport=self.port) / TFTP() # noqa: E501
self.last_packet = self.l3 / TFTP_WRQ(filename=self.filename, mode="octet") # noqa: E501
self.send(self.last_packet)
self.res = ""
self.awaiting = 0
raise self.WAITING_ACK()
# WAITING_ACK