1 year ago
#158676
Alex Montsarj
Network sniffer that opens the ips as tabs in browser?
I'm trying to write a code that basically grabs the network traffic sniffed by wireshark
and opens the ips in tabs in selenium
.
At first I tried using whois
and socket.gethostbyaddr()
as All I needed was to translate the ips to domains. But it didn't workout well.
I ran into a problem with permissions because pyshark
needs root privilege and selenium
doesn't work as root.
here is the code:
import pyshark
from selenium import webdriver
global ips
ips = ''
options = webdriver.ChromeOptions()
options.headless = False
options.add_argument("user-data-dir=/home/afterlife/Documents/chrome_profiles/cyber")
browser = webdriver.Chrome(executable_path='/home/afterlife/Downloads/chromedriver', options=options)
def get_domain_name(ip_address):
for line in ips:
if ip_address not in line:
ips += ip_address+'\n'
browser.execute_script('''window.open(''' + ip_address + ''',"_blank");''')
capture = pyshark.LiveCapture(interface="wlp1s0")
capture.set_debug()
for packet in capture.sniff_continuously():
try:
if hasattr(packet, 'http'):
protocol = packet.transport_layer
source_address = packet.ip.src
source_port = packet[packet.transport_layer].srcport
destination_address = packet.ip.dst
destination_port = packet[packet.transport_layer].dstport
print(destination_address)
get_domain_name(destination_address)
except:
print("exception")
I tried to make pyshark
work as non root but failed, I used sudo dpkg-reconfigure wireshark-common
but it haven't effected tshark
of pyshark
.
I also tried using os.setuid()
which I successfully used once but forgot/now it doesn't work. I used 0
for root and 1000
for my non-root user.
How would you accomplish what I want? Thank you!
python-3.x
selenium
tshark
setuid
pyshark
0 Answers
Your Answer