Home > OS >  Python on VSC (MacOs) running line of code with root/sudo permission (using Scapy)
Python on VSC (MacOs) running line of code with root/sudo permission (using Scapy)

Time:07-11

I'm running a port scanner algorithm on Python 3 using VSC on Mac. When running the Scapy function, or any other type of scanner, I get the following error: Scapy_Exception: Permission denied: could not open /dev/bpf0. Make sure to be running Scapy as root ! (sudo)

The code I am using

from scapy.all import *

ports = [25,80,53,443,445,8080,8443]

def SynScan(host):
    ans,unans = sr(IP(dst=host)/TCP(dport=ports,flags="S"),timeout=2,verbose=0)
    print("Open ports at %s:" % host)
    for (s,r,) in ans:
        if s.haslayer(TCP) and r.haslayer(TCP):
            if s[TCP].dport == r[TCP].sport:
                print(s[TCP].dport)

def DNSScan(host):
    ans,unans = sr(IP(dst=host)/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="google.com")),timeout=2,verbose=0)
    if ans:
        print("DNS Server at %s"%host)
    
host = "8.8.8.8"

SynScan(host)
DNSScan(host)

Any help is appreciated.

CodePudding user response:

Just run this script as root user.

sudo python script.py

do install scapy as root user.

  • Related