-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetip.py
78 lines (59 loc) · 1.87 KB
/
getip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import ftplib
from smtplib import SMTP
from dpkt.dns import DNS
from scapy.layers.dhcp import DHCP
from scapy.layers.inet import TCP, IP, UDP, ICMP
global ipvari
from scapy import all
from scapy.all import *
#import testfile
a = open("filepath.txt","r")
#dta stored in file using test .py can be accesed using filevar
filevar = str(a.readline())
a.close()
packets = scapy.all.rdpcap(filevar)
print(packets)
#This function is in order to get ipvari as output
def ipvarikafun():
for p in packets:
if p.haslayer(IP):
ipvari = p[IP].dst
return ipvari
def getipf():
#returns both source and destination ip address
ipvar =[]
src_ip=[]
for p in packets:
if p.haslayer(IP):
src_ip =p[IP].src
ipvar = p[IP].dst
return ipvar, src_ip
#getprotocol
def getprotocol():
protocol_name = []
for p in packets:
if p.haslayer(TCP):
print('TCP')
protocol_name.append('/TCP')
if p.haslayer(UDP):
print('UDP')
protocol_name.append(r'/UDP')
if p.haslayer(ICMP):
print('ICMP')
protocol_name.append(r'/ICMP')
if p.haslayer(ftplib.FTP):
print('FTP')
protocol_name.append((r'/FTP'))
if p.haslayer(DNS):
print('DNS')
protocol_name.append(r'/DNS')
if p.haslayer(SMTP):
print('SMTP')
protocol_name.append(r'/SMTP')
if p.haslayer(DNS):
print('DNS')
protocol_name.append(r'/DNS')
if p.haslayer(DHCP):
print('DHCP')
protocol_name.append(r'/DHCP')
return(protocol_name)