Skip to content

Instantly share code, notes, and snippets.

@shriphani
Created February 3, 2022 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shriphani/f98c212e0f4eb8d63ce3059a28509441 to your computer and use it in GitHub Desktop.
Save shriphani/f98c212e0f4eb8d63ce3059a28509441 to your computer and use it in GitHub Desktop.
import fcntl
import struct
import os
import requests
from scapy.all import *
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2
IFF_TAP = 0x0002
IFACE = 'tap1'
tun = open('/dev/net/tun', 'r+b', buffering=0)
ifr = struct.pack('16sH', bytes(IFACE, 'utf-8'), IFF_TAP)
fcntl.ioctl(tun, TUNSETIFF, ifr)
fcntl.ioctl(tun, TUNSETOWNER, 1000)
while True:
packet = os.read(tun.fileno(), 2048)
frame = Ether(packet)
frame.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment