0

I've tried to run this code using Pycharm in VirtualMachine Kali Linux and failed.

How to import scapy? I've also tried adding scapy to file > settings > ProjectInterpreter in Pycharm but it still doesn't work.

I'm sure I did install scapy using pip install scapy. What's the issue now?

Here the image of my screenshot

from scapy.all import *
        
def scan(ip):
    scapy.arping(ip)        

scan("10.0.2.1")
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
user126004
  • 3
  • 1
  • 5

4 Answers4

1

If someone is having the same issue after Udemy course. The exception is being thrown when you are trying to use it on python2, python3 network_scanner.py should solve the issue

Gleb L
  • 61
  • 1
  • 4
1

Actually I had this problem and the answer is really easy. First of all you need to see which version of pip do you have. you can try which pip and also try with which pip3. Next, when you open the terminal and and want to write your code if you have pyhton3 write on the command line 'python3 then from scapy.all import * will be okay to use.

0

first install the package with pip install scapy just use import scapy

or use from scapy import module_or_function_name

in your case use from scapy import arping

You don't need to use * here

Rajat Jog
  • 43
  • 1
  • 7
  • it is scapy, not scrapy – luigigi Mar 17 '20 at 07:14
  • Ohh but syntax is same use from scapy import arping – Rajat Jog Mar 17 '20 at 07:16
  • i did _sudo apt-get install scapy_ in my **virtualmachine kali linux** and shows this. **[sudo] password for kali: Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'python3-scapy' instead of 'scapy' python3-scapy is already the newest version (2.4.3-3). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.** – user126004 Mar 17 '20 at 07:20
  • This answer is wrong. You do need `scapy.all` or you need to use the sub module name directly... – Cukic0d Mar 17 '20 at 07:31
  • install with pip installer. check https://pypi.org/project/scapy – Rajat Jog Mar 17 '20 at 07:32
  • @Rajat Jog i did git clone https://github.com/secdev/scapy cd scapy ./run_scapy , what to do next? after i run it,it seems like a applications,i dont know how to use it :O – user126004 Mar 17 '20 at 07:42
  • go to directory "scapy" using cmd using '''cd scapy''' and the run the command "./run_scapy" – Rajat Jog Mar 17 '20 at 07:47
  • yeah i did ,after i type ./run_scapy it turns out a scapy app,i dont know how to describe it – user126004 Mar 17 '20 at 07:49
  • I'm assuming you have installed python with "pip" functionality. if yes, go to cmd and simply run the command pip install scapy. – Rajat Jog Mar 17 '20 at 07:51
  • @Rajat Jog cmd is for window , im running these thing in kali linux virtual machine – user126004 Mar 17 '20 at 07:53
  • @user126004 Go to terminal and run the same command. I'm also working on linux – Rajat Jog Mar 17 '20 at 07:59
  • i did `pip install scapy`,after that? what should i do , tried `from scapy import arping` but it turns our **No Module named Scapy** – user126004 Mar 17 '20 at 14:06
-2

The followings work without PyCharm:

from scapy.all import *

def scan(ip):
    scapy.layers.l2.arping(ip)

scan("10.0.2.1")

or

import scapy.all as scapy

def scan(ip):                                                                                                   
    scapy.arping(ip)

scan("10.0.2.1")

Just execute in terminal:

$ python3 network_scanner.py
duyanh92
  • 1
  • 1