Import Scapy.all - python

I want to know how to import scapy and use arping. I have tried import scapy.all and some others but has no seemed to work and I keep getting the error...
Traceback (most recent call last):
File "network_scanner.py", line 3, in <module>
from scapy.all import arping
ImportError: No module named scapy.all
This the code I am running.
#!/usr/bin/env python
from scapy.all import arping
def scan(ip):
arping(ip)
scan('10.0.2.1')
If someone could help me that would be amazing!

try to install scapy for ur python version. it seems like none scapy installed in your python lib.

Related

Unable to import scapy.all in python while root user

I have a python file named "test_module.py" with the code
from scapy.all import *
and when i execute the file with python test_module.py the module is getting imported successfully but when I run the file using the command sudo python test_module.py it is saying the error
Traceback (most recent call last):
File "test_module.py", line 1, in <module>
from scapy.all import *
ImportError: No module named scapy.all
System info:-
Linux mint 20
Python 2.7.18
So, Please help me to fix this issue.
Did you do
sudo python -m pip install scapy
first ? your issue is likely just having two separate environments
perhaps, try :
pip install scapy
import sys
# and take the correct Path to your scapy , example :
sys.path.insert(1, '/home/Your NAME/anaconda3/lib/python3.8/site-packages/')

Python 3: No module named 'tqdm'

I am using Raspberry PI 3 Model B running Kali Linux and i am currently coding a P2P encrypted python chat that runs on python 3. The cryptographic library i am using is called "CryptoShop", which is a '.py' file, not a imported library. I use it the same way that it's 'README' file instructed, so this is not a thing. Before i adeed crypto to the chat, it worked well, but now, i'm having errors since CryptoSHop uses the TQDM math library, and tryed installing it using APT-GET, PIP, by Source and nothing, because, firstly my chat only runs on Python3:
root#kali:~# python PyChat/pychat.py
File "PyChat/pychat.py", line 16
SyntaxError: Non-ASCII character '\xc3' in file PyChat/pychat.py on line 16, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
So when i use Python3:
root#kali:~# python3 PyChat/pychat.py
Traceback (most recent call last):
File "PyChat/pychat.py", line 4, in <module>
from cryptoshop import encryptstring
File "/root/PyChat/cryptoshop.py", line 52, in <module>
from tqdm import *
ModuleNotFoundError: No module named 'tqdm'
CryptoSHop try importing tqdm.
Here's a piece of it's code:
import os
import sys
from tqdm import *
import getpass
import argparse
I am still on the level of basic coding, i get this piece of chat code on the web, and just adeed to it basic user authentication (check if file whit the username exists), improved usability, and adeed crypto.
And sorry by my bad english, it's not my native language ;-)
Thanks in advance.
I am spanish, this happend when you use acents or special charts.
Add this in your first line:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
And use pip3 for install tqdm in python3
pip3 install tqdm

import libvirt in python but ImportError on Ubuntu

My os is Ubuntu 12.04.
I install the kvm virt-manager and python.
I want to use python code to control the vm on kvm.
but my code import libvirt has something wrong...
Here is my code :
import libvirt
import time
import threading
import paramiko
import os
import commands
import signal
numVM = 1
hostname=['VM-01']
port=22
VMLoadAve={}
def monitor():
.....
while True:
monitor()
time.sleep(MAXDURATION)
Traceback (most recent call last): File "test1.py", line 1, in
import libvirt ImportError: No module named libvirt
I have installed the python-libvirt, libvirt-bin
what other reasons may do this happened?
I am a newest for this. thanks for your help ~ :)
For the sake of historicaly record, 'python-libvirt' is the correct deb package for the python 2 binding, while python3-libvirt gives you the corresponding python 3 binding to libvirt.

global name 'GLib2Reactor' is not defined

I'm struggling to get some python code using the python-brisa framework to work, the code is not written by me but should be straight forward.
from brisa.core.reactors import install_default_reactor
reactor = install_default_reactor()
from brisa.core.threaded_call import run_async_function
import xml.etree.ElementTree as ET
from time import sleep
import sys, os
import sonos
import knx
Howewer after installing the frameworks I get
Traceback (most recent call last):
File "knxsonos.py", line 24, in <module>
reactor = install_default_reactor()
File "/usr/local/lib/python2.7/dist-packages/brisa/core/reactors/__init__.py", line 14, in install_default_reactor
return GLib2Reactor()
NameError: global name 'GLib2Reactor' is not defined
I have been looking both stack overflow, and googling for days without finding a solution.
Anyone??, help would be greatly appreciated...
Here's some possibilities:
GLib2Reactor doesn't return anything - Then your code is wrong
GLib2Reactor is not declared - try this:
x = GLib2Reactor()
return x
GLib2Reactor has to be imported - just import it
my best advice: read the docs
When I saw this problem on an Ubuntu Trusty (14.04) system, it was caused by import gobject failing. The fix was to install the correct package:
sudo apt-get install python-gobject-2
This package is marked as deprecated, so on newer distributions it might be necessary to install the python-gi package instead, and then modify the callers to use the new names:
from gi.repository import GObject

Scapy.all import * does not work

So, I wrote a little script in Ubuntu for scapy.
#!/usr/bin/env python
import sys
#from scapy.all import *
try
import scapy
except ImportError:
del scapy
from scapy import all as scapy
i= IP()
t= TCP()
i.dst='192.168.56.100'
t.dport=22
pakket=i/t
answered,unanswered=sr(pakket)
answered.nsummary()
i wrote the 'try' because of another topic here (tried it as a solution).
My current output with this code is the following
Traceback (most recent call last):
File "./scapy.py", line 5, in <module>
import scapy
File "/home/nicholas/scapy.py", line 9, in <module>
i=IP()
NameError: name 'IP' is not defined
when trying it just with from scapy.all import * withouth the 'try'.
Traceback (most recent call last):
File "./scapy.py", line 3, in <module>
from scapy.all import *
File "/home/nicholas/scapy.py", line 3, in <module>
from scapy.all import *
ImportError: No module named all
I tried different ways of importation found on Google but it still doesn't work. Could anyone please tell me what I'm doing wrong? (don't mind the indentation of this post)
From looking at scapy source, the scapy package doesn't appear to import anything or define an __all__ in __init__. As a result, you need to explicitly import scapy.all (or from scapy import all) before you can from scapy.all import anything else from it, as it won't be in sys.modules yet. Note that this only has to happen once in your program flow though, as after the interpreter imports the module, it will be available to all code that executes from then on, regardless of where it is. Take a look at the Python docs on modules and how import, and specifically importing a package, works for more details.
Edit:
I think I see the problem now, I just was paying attention to the wrong part of your stack trace. Pretty sure what you are dealing with here is a name collision. Your file is named scapy.py, so when you import scapy from the context of that file, you are actually importing the file itself as a module. Since your file does not have a submodule named all (it can't, since it's not a package), you get the import error you are seeing. Try switching the name of your file to something that does not conflict with any packages or modules you wish to import inside it, and see if that works out better.
By the way, note in your stack traces that your import is actually essentially recursively calling your one file. That should be a clue that something has gone haywire in the import process.
I had a similar problem on OSX, I installed the scapy package pip install scapy and then I was trying to execute my test file scapy.py The error I got was :
python scapy.py
Traceback (most recent call last):
File "scapy.py", line 1, in <module>
from scapy.all import *
File "/Users/**/Desktop/scapy-test/scapy.py", line 1, in <module>
from scapy.all import *
ModuleNotFoundError: No module named 'scapy.all'; 'scapy' is not a package
In my case, it was the file name itself that caused the problem it can't be called scapy.py. I change it to test.py and all worked, it had nothing to do with the package location just the file name.
I like to add something to #Daniel answer. Your real problem is not scapy package. Your real problem is in your python file name. Don't ever use library name or its contents as your file name.
In your case, your file name is scapy.py. After that you import scappy. In here you accidentally call your python file as object in your code there for your compiler can't understand which type(file or library) to call. There for that error was appeared.
I saw this when I had a scapy.py in the current directory. scapy.all import * seems to look in the current directory first.
The correct import with current versions would be:
from scapy.all import *

Categories

Resources