pyshark can not capture the packet on windows 7 (python)

2024/9/23 6:12:32

I want to capture the packet using pyshark. but I could not capture the packet on windows 7.

this is my python code


import pyshark
def NetCap():print 'capturing...'livecapture = pyshark.LiveCapture(interface="eth0", output_file='./test.pcapng')livecapture.sniff(packet_count=10)print 'end of capture.'print livecaptureif __name__ == "__main__":NetCap()

this is result


capturing...
end of capture.
<LiveCapture (0 packets)>

Livecapture is 0 packets. I don't know what is the matter. please help me.

Answer

open cmd then go to C:\Program Files\Wireshark and type:

tshark -D

this will give you a list like:

C:\Program Files\Wireshark>tshark -D
1. \Device\NPF_{BF2D596D-AEB8-4AF3-88A2-FF31441BB262} (VMware Network Adapter VMnet8)
2. \Device\NPF_{7AB58B39-455D-4A40-AA3A-678491E70B27} (Local Area Connection* 4)
3. \Device\NPF_{7FEC3EE6-0676-4E81-8B13-FBD5716BF2BF} (Wi-Fi)
4. \Device\NPF_{10D9C98D-BF03-4CE5-A58C-5A726BC6066A} (Ethernet)
5. \Device\NPF_{45AD9B2A-DB01-4EDE-A922-C2DD6D868568} (VMware Network Adapter VMnet1)
6. \\.\USBPcap1 (USBPcap1)

now you can use any of the interface as required by this:

import pyshark
livecapture = pyshark.LiveCapture(interface='\\Device\\NPF_{7FEC3EE6-0676-4E81-8B13-FBD5716BF2BF}', output_file='./test.pcapng')
https://en.xdnf.cn/q/71852.html

Related Q&A

How to get the Signal-to-Noise-Ratio from an image in Python?

I am filtering an image and I would like to know the SNR. I tried with the scipy function scipy.stats.signaltonoise() but I get an array of numbers and I dont really know what I am getting.Is there an…

Python and OpenCV - Cannot write readable avi video files

I have a code like this:import numpy as np import cv2cap = cv2.VideoCapture(C:/Users/Hilman/haatsu/drive_recorder/sample/3.mov)# Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_…

Python as FastCGI under windows and apache

I need to run a simple request/response python module under an existing system with windows/apache/FastCGI.All the FastCGI wrappers for python I tried work for Linux only (they use socket.fromfd() and …

Scrapy shell return without response

I have a little problem with scrapy to crawl a website. I followed the tutorial of scrapy to learn how crawl a website and I was interested to test it on the site https://www.leboncoin.fr but the spide…

How to replace values using list comprehension in python3?

I was wondering how would you can replace values of a list using list comprehension. e.g. theList = [[1,2,3],[4,5,6],[7,8,9]] newList = [[1,2,3],[4,5,6],[7,8,9]] for i in range(len(theList)):for j in r…

Installed PySide but cant import it: no module named PySide

Im new to Python. I have both Python 2.7 and Python 3 installed. I just tried installing PySide via Homebrew and got this message:PySide package successfully installed in /usr/local/lib/python2.7/sit…

How to run SQLAlchemy on AWS Lambda in Python

I preapre very simple file for connecting to external MySQL database server, like below:from sqlalchemy import *def run(event, context):sql = create_engine(mysql://root:[email protected]/scraper?chars…

saving csv file to s3 using boto3

I am trying to write and save a CSV file to a specific folder in s3 (exist). this is my code: from io import BytesIO import pandas as pd import boto3 s3 = boto3.resource(s3)d = {col1: [1, 2], col2: […

httplib2, how to set more than one cookie?

As you are probably aware, more often than not, an HTTP server will send more than just a session_id cookie; however, httplib2 handles cookies with a dictionary, like this:response, content = http.requ…

FTP upload file works manually, but fails using Python ftplib

I installed vsFTP in a Debian box. When manually upload file using ftp command, its ok. i.e, the following session works:john@myhost:~$ ftp xxx.xxx.xxx.xxx 5111 Connected to xxx.xxx.xxx.xxx. 220 Hello,…