I want to access data in pap packets, currently i'm using pyshark with the following code
import pyshark,sys
cap = pyshark.FileCapture('test.pcap',display_filter='ppp && not ppp.length')
for packet in cap:
if packet.pap.get_field_value('peer_id'):
print ('user: '+packet.pap.peer_id+" logged in")
and it works fine on my pc and raspberrypi unfortunately i want to use this code on openwrt/lede router on which pyshark can't be installed due to ccache error:
unable to execute 'ccache_cc': no such file or directory
which i assumed that openwrt lacks some compiler features so I tried to install other pcap parsing libraries and could install scapy, dpkt and pypcapfile and they all installed fine so how can I convert my code to use one of these libraries
Thanks to #pierre I found out that the development version of scapy has some new usefull classes (PPP_PAP and PPP_PAP_Request) so I was able to write a working code for my problem and it works in python2 and python3
from scapy.all import PPP,PPP_PAP_Request,sniff
def logusers(pkt):
if PPP_PAP_Request in pkt:
print(pkt[PPP_PAP_Request].username.decode()+" logged in")
sniff(count=0,offline='all.pcap',prn=logusers,filter="pppoes",store=0)
I used sniff function because i found it a bit lightweight and fast(i'm trying to run the code on an embedded system after all) But nevertheless it's still a bit slow and i don't know if there is something faster (maybe other than scapy) so i'm not going to accept this answer for a while
With Scapy (use the development version from GitHub), you can try:
from scapy.all import PcapReader, PPP_PAP_Request
for pkt in PcapReader('test.pcap'):
if PPP_PAP_Request in pkt:
print(pkt.sprintf('user: %PPP_PAP_Request.username% logged in'))
Related
I have a DeLorme Earthmate LT-40 USB GPS device that I used years ago with a Windows XP program. Out of curiosity I plugged it into my Raspberry Pi to see if I could read the data. I've managed to see data using sudo gpsmon at the command prompt so I would like to take this a step further and write a Python program to read the data. Not knowing very much about Python I've searched YouTube and google for possible solutions. It looks like that I need to import pynmea2. I used pip install pynmea2 to install the module. I keep getting
"ModuleNotFoundError: No module named pynmea2"
when I try to run my script. I tried to reinstall pynmea2 again which gave me
Requirement already satisfied: pynmea2 in ./.local/lib/python2.7/site-packages(1.15.0).
I don't understand what I'm doing wrong. Any help would be greatly appreciated. Thank you.
I have the older version LT-20 of that GPS and usually it presents itself as ttyUSB0 (in my case) when I plug it on Raspberry.
Just do a dmesg command to see in which port it is being recognized, then you can do a cat /dev/ttyUSB0 command and you see all the messages coming from your GPS. The messages start with a $GP for each type of frame. See detailed $GP description at: http://aprs.gids.nl/nmea/ .
Then from your python program, you can open /dev/ttyUSB0 as a file (as read only) and handle each frame and interpetting it according to its format.
Best regards
Flavio
I am trying to analyze currency data using MT5 in Python but it is not working. I didn't understand where is the problem? even importing is not work
from MetaTrader5 import *
from datetime import date
# Initializing MT5 connection
MT5Initialize()
MT5WaitForTerminal()
print(MT5TerminalInfo())
print(MT5Version())
This is the error: MT5WaitForTerminal()RuntimeError: No IPC connection
I had the same issue and I found the following solution:
My terminal was downloaded from the broker site and probably had some modifications that block ipc connections.
I downloaded original software from https://www.metatrader5.com/en/download
and copied "Config" folder from broker's version.
Now python script works.
I have a computer with a Windows 10 64-bit installation where everything would work without a hitch. I also have another machine with a Windows 10 32-bit installation, which would always complain about an invalid IPC connection. Not the official MetaTrader 5 version, nor my broker's customized version would work out of the box.
I eventually fixed it by specifying the path to my broker's exe in the initialize function like below (check for your own path, and mind the use of / instead of \):
mt5.initialize("C:/Program Files (x86)/GT247/terminal.exe")
I installed python 2.7 and scapy following the supported programs: pywin32, WinPcap, Pypcap and libdnet. I feel that it is important to say that my OS is windows 7.
When I am using the function sniff it appears to raise an error: http://prntscr.com/dbd79a. I have tried another scapy's function and classes as IP and sendp and it works fine, the problem is only on sniff.
I have tried several versions of scapy from many installations links and no change.
Your problem is a bug in version 2.3.3 of scapy (uploaded on 18/10/16).
It will probably be fixed in the next version, in the meantime you can install the previous version by doing
pip install scapy==2.3.2
I checked in the commits and this bug wasnt in that version. However i havent tested it so it might contain other bugs (as 2.3.3 must have changed something for the better, atleast i hope it did), so if you must use 2.3.3 for some reason you can patch it around like this:
from scapy.arch.windows import compatibility
from scapy.all import log_runtime, MTU, ETH_P_ALL, PcapTimeoutElapsed, plist
compatibility.log_runtime = log_runtime
compatibility.MTU = MTU
compatibility.PcapTimeoutElapsed = PcapTimeoutElapsed
compatibility.ETH_P_ALL = ETH_P_ALL
compatibility.plist = plist
compatibility.sniff(1) # call the sniff function however you like
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
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.