def main(): # Ethernet header eth = ethernet.Ethernet() eth.src = b"\x00\x0c\x29\xdf\xe3\xc0" eth.dst = b"\x00\x0c\x29\x29\x85\xd2" eth.type = ethernet.ETH_TYPE_IP # IP header ipp = ip.IP() ipp.src = socket.inet_aton("172.16.13.165") ipp.dst = socket.inet_aton("172.16.13.162") ipp.p = ip.IP_PROTO_TCP # TCP header tcpp = tcp.TCP() tcpp.sport = 60001 tcpp.dport = 80 tcpp.flags = tcp.TH_SYN ipp.data = tcpp ipp.len = len(str(ip)) ipp.id = 1 tcpp._TCP__calc_sum() ipp._IP__calc_sum() eth.data = ipp # open sockets using the socket handler sock_l2 = SocketHndl(iface_name="eth1", mode=SocketHndl.MODE_LAYER_2) # send raw bytes sock_l2.send(eth.bin())
class IterClass(object): """ Wrapper class to iterate over packets from psocket """ def __init__(self): self.psock = SocketHndl(iface_name="mon0", timeout=10) def __iter__(self): while True: try: yield self.psock.recvp(lowest_layer=radiotap.Radiotap)[0] except Exception as e: print(e) continue self.psock.close()
class IterClassSocket(object): """ Wrapper class to iterate over packets from psocket """ def __init__(self): self.psock = SocketHndl(iface_name="wlan0", timeout=10) def __iter__(self): while True: try: yield self.psock.recvp()[0] except StopIteration: break except: continue self.psock.close()
class IterClassSocket(object): """ Wrapper class to iterate over packets from psocket """ def __init__(self): self.psock = SocketHndl(iface_name="wlan0", timeout=10) def __iter__(self): while True: #time.sleep(0.5) try: yield self.psock.recvp()[0] except StopIteration: break except: continue self.psock.close()
def test_socket(self): print_header("Sockets") packet_eth = ethernet.Ethernet() +\ ip.IP(src_s="192.168.178.27", dst_s="173.194.113.183") +\ tcp.TCP(dport=80) packet_ip = ip.IP(src_s="192.168.178.27", dst_s="173.194.113.183") + tcp.TCP(dport=80) # Layer 2 Socket socket = SocketHndl(iface_name="eth1", mode=SocketHndl.MODE_LAYER_2) #socket.send(packet_eth.bin()) packets = socket.sr(packet_eth) for p in packets: print(">>> %s" % p) socket.close() # Layer 3 Socket socket = SocketHndl(iface_name="eth1", mode=SocketHndl.MODE_LAYER_3) #socket.send(packet_ip.bin()) packets = socket.sr(packet_ip) for p in packets: print(">>> %s" % p) socket.close()
def __init__(self): self.psock = SocketHndl(iface_name="mon0", timeout=10)