本文整理汇总了Python中scapy.supersocket.SuperSocket类的典型用法代码示例。如果您正苦于以下问题:Python SuperSocket类的具体用法?Python SuperSocket怎么用?Python SuperSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SuperSocket类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
def send(self, x):
pkt_src_mac_field,pkt_src_mac_val = x.getfield_and_val('src')
if self.__use_iface and pkt_src_mac_val is None:
iff = self.iface
if iff:
try:
src_mac = scapy.arch.get_if_hwaddr(iff)
except:
pass
if src_mac is None:
src_mac = "00:00:00:00:00:00"
x.src = scapy.fields.MACField.i2h(pkt_src_mac_field, x, src_mac)
if x.haslayer('IP') :
pkt_src_ip_field,pkt_src_ip_val = x['IP'].getfield_and_val('src')
if isinstance(pkt_src_ip_field,scapy.fields.Emph):
pkt_src_ip_field = pkt_src_ip_field.fld
if self.__use_iface and pkt_src_ip_val is None:
iff = self.iface
if iff:
try:
src_ip = scapy.arch.get_if_addr(iff)
except:
pass
x['IP'].src = scapy.fields.SourceIPField.i2h(pkt_src_ip_field, x, src_ip)
SuperSocket.send(self, x)
示例2: close
def close(self):
if self.closed:
return
self.closed = 1
if self.promisc:
set_promisc(self.ins, self.iface, 0)
SuperSocket.close(self)
示例3: send
def send(self, x):
try:
return SuperSocket.send(self, x)
except socket.error as msg:
if msg[0] == 22 and len(x) < conf.min_pkt_size:
padding = b"\x00" * (conf.min_pkt_size - len(x))
if isinstance(x, Packet):
return SuperSocket.send(self, x / Padding(load=padding))
else:
return SuperSocket.send(self, raw(x) + padding)
raise
示例4: __init__
def __init__(self, peer="127.0.0.1"):
SuperSocket.__init__(self, socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.outs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.tx_addr = (peer, 52001)
self.rx_addr = (peer, 52002)
self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except AttributeError:
pass
self.ins.bind(self.rx_addr)
示例5: send
def send(self, x):
try:
if hasattr(x, "sent_time"):
x.sent_time = time.time()
# need to change the byteoder of the first four bytes,
# required by the underlying Linux SocketCAN frame format
bs = bytes(x)
bs = bs + b'\x00' * (CAN_FRAME_SIZE - len(bs))
bs = struct.pack("<I12s", *struct.unpack(">I12s", bs))
return SuperSocket.send(self, bs)
except socket.error as msg:
raise msg
示例6: recv
def recv(self, x=MTU):
# cls, pkt, ts, direction = self.recv_raw()
# [Dissection stuff]
pkt = SuperSocket.recv(self, x)
# pkt.direction = direction
return pkt
示例7: close
def close(self):
SuperSocket.close(self)
self.usbpcap_proc.kill()