Pydev with Scapy Gives "Unresolved Import" Error - python

I'm trying to write a program that uses the scapy modules. I'm using PyDev for my development but it keeps giving me errors when I import certain parts of the Scapy module. I'm pretty sure I have my import paths in PyDev set up correctly. I've looked at some of the other questions involving "Unresolved Import" errors on here. However, none of the suggestions I saw seemed to help.
The weird thing is that it is only part of the scapy modules that don't work. So for instance PyDev doesn't complain when I do
from scapy.all import Ether, sendp
However, when I do
from scapy.all import IP, UDP
I get errors.
I thought maybe I was importing the wrong modules but when I go to the interpreter and type in the second example it gives no errors and then I can create IP packets using IP(params), which is what I'm trying to do in my program.
I installed scapy using the ubuntu repositories, but when I started having import problems I downloaded the latest version from scapy.net and used the setup script. I even copied the zip and put it in my /usr/local/lib/python2.7/site-packages folder and added it to my python path in PyDev. But nothing seems to get rid of the error.
Any suggestions on what could be causing this and how to fix it?

Have you tried adding 'scapy' to the forced builtins? See: http://pydev.org/manual_101_interpreter.html for details.

I got a chance to play some more with this. I still don't know why PyDev gives me an import error when it works fine in the interpreter, however, I did find a way around it. To import things like IP, UDP, and TCP I'm now using the following
from scapy.layers.inet import IP, TCP, UDP
For non IPv4 stuff
from scapy.all import <Module Name>
seems to work just fine.

Related

ModuleNotFoundError: No module named 'paho'

I am trying to make connection with my raspberry Pi and my PC windows through MQTT protocol. And I have a problem I cant solve on my PC - I can t import library that I have installed to my program:
import paho.mqtt.client as mqtt
Results in the error
ModuleNotFoundError: No module named 'paho'
The topic was already issued here (Import Error: paho.mqtt.client not found), but solution doesnt work for me.
I see it in the python folder:
C:\Users\mhucl\AppData\Local\Programs\Python\Python310\Lib\site-packages\paho\mqtt\client
I see it in the pip list. But the program can t find it. Do you know where could be the problem? I use python version 3.10.3. I tried it on different PC aswell and the same result. I followed all solutions on youtube, forums and nothing. Thank you very much.
Here are screenshots if someone would like to see:
https://uschovna.cz/zasilka/WLUWM5TNP7HP7GDG-XKP/UCKZFIZHCI
pip install paho-mqtt
https://pypi.org/project/paho-mqtt/
I solved my error by using this command

Import module failed even though installed

i have a couple of different questions regarding importing modules and another non-related syntax question.
So, i'm using a module called netmiko to automate networking scripts, this isn't a networking question but a python one, i create the scripts in Pycharm and then run them but when i tried to do one last night for the first time using Netmiko it's coming up with an import module failed exception which is confusing me because i've installed it using "pip install netmiko" and i saw it install AND if i do "import netmiko" using the command line on Windows then it works as well with no exceptions. So i've been building the scripts in Pycharm but having to copy/paste them into then cli which isn't great. Does anybody know what the issue may be here?
The second question is just a general syntax question. I've seen "+=" used when using the same variable names in Python (mainly used in netmiko scripts but i assume it's obviously used in other Python scripts to) such as:
output = net_connect.send_command(cmd, expect_string=r'Destination filename')
output += net_connect.send_command('\n', expect_string=r'#')
....the rest of the script isn't import, but i'm wondering what the "+=" is actually doing here because to me it seems no different than doing:
output = net_connect.send_command(cmd, expect_string=r'Destination filename')
output = net_connect.send_command('\n', expect_string=r'#')
Can anyone shed some light on this as well?
Thanks as usual everyone!!

Python 2.7.15 Module 'ssl' not working properl

Recently, I have been working on some python (2) programs that require me to connect to a 'https' site. To do this I have been using the ssl module to wrap sockets etc.
import ssl
ssl_socket = ssl.wrap_socket(...)
I have also been using the urllib2 module to do this automatically, which to my knowledge, requires httplib and ssl etc. However, just today, I have been using it again exactly in the same way but now a lot of the functions in the ssl module have just... well, disappeared? On my other Linux machine when I execute:
import ssl
dir(ssl)
It brings back at least 50 odd classes and sub functions for it such as "wrap_socket" and "_create_default_https_context"; functions that are required for me at the moment. Now however, since today, I have been using it in exactly the same way, which now for some reason does not have the functions "wrap_socket" or "_create_default_https_context". And also now when I execute:
import ssl
dir(ssl)
It only brings back:
['__builtins__', '__doc__', '__file__','__name__','__package__','extractor', 'httplib', 're', 'request', 'socket', 'ssl']
Instead of about 10X more functions than when it was working? I have tried reinstalling python, updating it, reinstalling the whole machine (Linux) and the same thing happens. I am very lost as to why this is happening and it is a pain because the urllib2 and httplib modules require the ssl module to work on "https" sites. Any help would be really appreciated. Thanks :) Pete.

Python import of firebase module causes program to loop unexpectedly

So, using the python-firebase pip module, the following code:
from firebase import firebase
print 'test'
Causes the following output:
test
test
test
test
test
Commenting out the import, or importing any other modules, causes test to be printed only once as expected. This is happening on my 2 windows machines at home, with different version of python. My linux boxes at work are not showing this behavior. Extremely weird. Anybody know what could possibly be going on?
The pip install of firebase hasnt been updated and has some bugs in it. Take the latest version from Github you should be fine after using this version.
There is a very good blog post on getting started with this python-firebase here burhan.io check it out :-)
V

pcapy.findalldevs() No valid interfaces to open

I am trying to run Sulley's (the fuzzer) "network_monitor.py" on an Ubuntu vm. Everytime I do, I get the following error.
pcapy.PcapError: No valid interfaces to open
I believe that this has little to do with the code I am running it in, because when I run
python
>>> import pcapy
>>> devices = pcapy.findalldevs()
I get the same error
Any hints on what's going on would be amazing. Thanks so much in advance
Try to use it with sudo.
Pcapy, AFAIK, needs special rights to access interfaces.
mycode.py:
import pcapy
devices = pcapy.findalldevs()
sudo python mycode.py

Categories

Resources