0

I have been writing a network scanner using pycharm and it seems to be having issues when trying to run the code:

As with all of my other post I have googled excessively but have not found out how to fix the problem yet.

I have tried this using windows and parrotsec using pycharm, downloaded previous versions of scapy but nothing seems to work?

pycharm: 2019.3.4 x64

python version: 2 and 3 downloaded - most up to date versions

scapy versions tried: 2.2.0-dev to 2.4.3

window: 10

parrotsec: 4.8

Below is the error I am getting when I run this in the terminal.

Traceback (most recent call last):
  File "network_scanner.py", line 26, in <module>
    scan_result = scan("192.168.0.64/24")
  File "network_scanner.py", line 13, in scan
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
  File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 504, in srp
    filter=filter, nofilter=nofilter, type=type)
  File "/usr/lib/python2.7/dist-packages/scapy/arch/linux.py", line 467, in __init__
    self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501
  File "/usr/lib/python2.7/socket.py", line 191, in __init__
    _sock = _realsocket(family, type, proto)
socket.error: [Errno 1] Operation not permitted
import scapy.all as scapy

def get_arguments():
    parser = optparse.OptionParser()
    parser.add_option("-t", "--target", dest="target", help="Target IP / IP range.")
    options, arguments = parser.parse_args()
    return options

def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast / arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    clients_list = []
    for element in answered_list:
        client_dict = {"ip": element[1].psrc, "mac address": element[1].hwsrc}
        clients_list.append(client_dict)
    return clients_list

def print_result(results_ist):
    print("IP\t\t\tMAC Address\n-----------------------------------------")
    for client in results_ist:
        print(client["ip"] + "\t\t" + client["mac address"]) 

useful comments that actually help would be amazing.

Thanks

Ooo
  • 39
  • 9

1 Answers1

0

Fixed the issue, change the optparse to the new update argparse, uninstalled scapy and reinstalled with the below commands in terminal.

To run the code python3 network_scanner.py -t (IP)

Re install scapy using the following commands:
pip uninstall scapy-python3
pip uninstall scapy
pip install scapy
pip3 install scapy
#!/usr/bin/env python

import scapy.all as scapy
import argparse

def get_arguments():
    parser = argparse.ArgumentParser()
    parser.add_argument("-t", "--target", dest="target", help="Target IP / IP Range.")
    options = parser.parse_args()
    return options

def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast / arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    clients_list = []

    for element in answered_list:
        client_dict = {"ip": element[1].psrc, "mac address": element[1].hwsrc}
        clients_list.append(client_dict)
    return clients_list

def print_result(results_ist):
    print("IP\t\t\tMAC Address\n-----------------------------------------")
    for client in results_ist:
        print(client["ip"] + "\t\t" + client["mac address"])

options = get_arguments()
scan_result = scan(options.target)
print_result(scan_result)
Ooo
  • 39
  • 9