Created
March 9, 2024 12:48
-
-
Save Pymmdrza/41db65a6a0c8e19f49e6989eaff50c6a to your computer and use it in GitHub Desktop.
Grab and Real Time Check All Packet Upload and Download in Windows With Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# // first install package | |
# // pip install pyshark colorthon | |
import pyshark, math, time | |
from colorthon import Colors as Fore | |
# return time local with import time | |
def getTimer(): | |
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) | |
def getSize(bytesNumber): | |
if bytesNumber == 0: | |
return "0B" | |
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") | |
i = int(math.floor(math.log(bytesNumber, 1024))) | |
p = math.pow(1024, i) | |
s = round(bytesNumber / p, 2) | |
return "%s %s" % (s, size_name[i]) | |
def packet_callback(packet): | |
if hasattr(packet, 'ip'): | |
src_ip = packet.ip.src | |
dst_ip = packet.ip.dst | |
packet_length = packet.length | |
sizer = getSize(int(packet_length)) | |
print( | |
f"[{Fore.RED}{getTimer()}{Fore.RESET}] Source IP: {Fore.CYAN}{src_ip}{Fore.RESET} Destination IP:{Fore.YELLOW} {dst_ip}{Fore.RESET} Packet Length: {Fore.GREEN}{sizer}{Fore.RESET} ") | |
capture = pyshark.LiveCapture(interface='Ethernet') | |
for packet in capture.sniff_continuously(): | |
packet_callback(packet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment