from scapy.all import * import time def handle_pppoe(pkt): if PPPoEDiscovery in pkt and pkt[PPPoEDiscovery].ptype == 0x57: print("Received PPPoE Discovery Request") mac_src = pkt[Ether].src pppoe_sess_id = pkt[PPPoEDiscovery].sessionid print(f"MAC: {mac_src}, Session ID: {pppoe_sess_id}") # Create PPPoE Session Confirmation packet pppoe_sess_conf = Ether(src=get_if_hwaddr("eth0"), dst=mac_src) / \ PPPoE(sessionid=pppoe_sess_id) / \ PPP(proto=0xc021) # Send PPPoE Session Confirmation sendp(pppoe_sess_conf, iface="eth0") print("Sent PPPoE Session Confirmation") # Delay to simulate PPPoE connection process time.sleep(2) # Create DHCP Discover packet dhcp_discover = Ether(src=get_if_hwaddr("eth0"), dst="ff:ff:ff:ff:ff:ff") / \ IP(src="0.0.0.0", dst="255.255.255.255") / \ UDP(sport=68, dport=67) / \ BOOTP(chaddr=mac_src) / \ DHCP(options=[("message-type", "discover"), "end"]) # Send DHCP Discover sendp(dhcp_discover, iface="eth0") print("Sent DHCP Discover") sniff(prn=handle_pppoe, filter="ether proto 0x8863 or ether proto 0x8864", iface="eth0")