updated wifi_diag_python

This commit is contained in:
SushantBawiskar
2020-10-01 20:22:48 +05:30
parent 2a35449ea5
commit a2c3d2dbe5
3 changed files with 492 additions and 186 deletions

View File

@@ -19,7 +19,7 @@ class Plot:
# print("In Plot")
pass
def bar(self, datax="", datay=" ", title="Temp", xaxis="xaxis", yaxis="yaxis",figname="temp"):
def bar(self, datax="", datay=" ", title="Temp", xaxis="yaxis", yaxis="xaxis",figname="temp"):
# fig = plt.figure()
self.tmpfile = BytesIO()

View File

@@ -48,106 +48,106 @@ def htmlobj(text):
def htmlpointview():
pointview = """
<!--For Point view -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
ul, #myUL {
list-style-type: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">\n
<style>\n
ul, #myUL {\n
list-style-type: none;\n
}\n
#myUL {
margin: 0;
padding: 0;
}
#myUL {\n
margin: 0;\n
padding: 0;\n
}\n
.box {
cursor: pointer;
-webkit-user-select: none; /* Safari 3.1+ */
-moz-user-select: none; /* Firefox 2+ */
-ms-user-select: none; /* IE 10+ */
user-select: none;
}
.box {\n
cursor: pointer;\n
-webkit-user-select: none; /* Safari 3.1+ */\n
-moz-user-select: none; /* Firefox 2+ */\n
-ms-user-select: none; /* IE 10+ */\n
user-select: none;\n
}\n
.box::before {
content: "\\2610";
color: black;
display: inline-block;
margin-right: 6px;
}
.box::before {\n
content: "\\2610";\n
color: black;\n
display: inline-block;\n
margin-right: 6px;\n
}\n
.check-box::before {
content: "\\2611";
color: dodgerblue;
}
.check-box::before {\n
content: "\\2611";\n
color: dodgerblue;\n
}\n
.nested {
display: none;
}
.nested {\n
display: none;\n
}\n
.active {
display: block;
}
.active {\n
display: block;\n
}\n
* {
box-sizing: border-box;
}
* {\n
box-sizing: border-box;\n
}\n
.column {
float: left;
width: 100%;
.column {\n
float: left;\n
width: 100%;\n
}
}\n
.row::after {
content: "";
clear: both;
display: table;
}
.row::after {\n
content: "";\n
clear: both;\n
display: table;\n
}\n
.borderexample {
border-style:solid;
border-color: hsl(0, 0%, 73%);
}
.btn {
background-color: DodgerBlue;
border: none;
color: white;
padding: 12px 30px;
cursor: pointer;
font-size: 20px;
}
.borderexample {\n
border-style:solid;\n
border-color: hsl(0, 0%, 73%);\n
}\n
.btn {\n
background-color: DodgerBlue;\n
border: none;\n
color: white;\n
padding: 12px 30px;\n
cursor: pointer;\n
font-size: 20px;\n
}\n
/* Darker background on mouse-over
.btn:hover {
background-color: RoyalBlue;
}
</style>
</head>
/* Darker background on mouse-over */
.btn:hover {\n
background-color: RoyalBlue;\n
}\n
</style>\n
</head>\n
"""
html.write(str(pointview))
def htmlTableSummary(Summary):
tableSummary = "<body><!-- This is heading and Summary --><h2> About: </h2> \
tableSummary = "<body><!-- This is heading and Summary --><h2> About: </h2> \n \
<p>"+str(Summary)+"</p> \n"
html.write(str(tableSummary))
def myUL():
html.write("<ul id='myUL'>")
html.write("<ul id='myUL'> \n")
def htmlSpanBox(Table):
tablespan = "<li><span class= 'box borderexample'>"+str(Table)+"</span> <ul class='nested'> "
tablespan = "<li><span class= 'box borderexample'>"+str(Table)+"</span> <ul class='nested'> \n"
html.write(tablespan)
def htmlSpanBox1():
tablespan = "<li><span class='box'> Table </span> <ul class='nested'> "
tablespan = "<li><span class='box'> Table </span> <ul class='nested'> \n"
html.write(tablespan)
def htmltable(Heading,data,image1,image2,image3):
def htmltable(Heading,data,image1,image2,image3,summary):
# htmlBreak(1)
htmlSpanBox(Heading)
htmlTableSummary("This is table summary below Objective \n")
htmlSpanBox1()
htmlTableSummary(str(summary)+"\n")
# htmlSpanBox1()
html.write("<li><span> ")
html.write(str(data))
html.write("</span></li> ")
@@ -223,10 +223,8 @@ def htmlSpace(space):
</style>"""
html.write(Space)
def htmlText(text, title):
title = "<h2" + str(title) + "</h2>"
def htmlText(text):
data = "<p>" + str(text) + "<p/>"
html.write(title)
html.write(data)

View File

@@ -76,19 +76,19 @@ def PacketHistogram(subtype_list, Managementls, Controlls, Data_framels, count):
NewPerList = per_list
# NewPerList.append(sum(NewPerList))
print(len(subtype_list),len(NewSubList),len(pack_list),print(NewPerList))
df_Type = pd.DataFrame(({"Type": Type_list, "Subtype": NewSubList, "Packet to packet": pack_list, "Percentage": NewPerList}))
# print(len(subtype_list),len(NewSubList),len(pack_list),print(NewPerList))
df_Type = pd.DataFrame(({" Type ": Type_list, " Subtype ": NewSubList, " Total Packets ": pack_list, "Percentage": NewPerList}))
# print("df_Type",df_Type)
df_Type = df_Type.to_html()
df_Type = df_Type.to_html(index=False)
# NewPerList.pop()
# NewSubList.pop()
plot = Plot()
path = plot.bar(datax=NewSubList,datay=NewPerList,title="Type/SubType plot",xaxis="Subtype",yaxis="Percentage",figname="Type")
htmltable(" Packet Type histogram", df_Type, str(path), "0", "0")
htmltable(" Packet Type histogram", df_Type, str(path), "0", "0","Summary ")
@@ -121,12 +121,12 @@ def RateHistogram(DataRate, PhyType, SignalStrength, count):
df_Rate = pd.DataFrame({"Rate MBPS": [i for i in dictRate.keys()], "Packet to packet": [j for j in dictRate.values()], "Percentage": [k for k in perUniqueData]})
df_Rate = pd.DataFrame({" Rate MBPS ": [i for i in dictRate.keys()], " Total Packets ": [j for j in dictRate.values()], " Percentage ": [k for k in perUniqueData]})
df_Rate = df_Rate.T
df_Rate.columns = df_Rate.iloc[0]
df_Rate = df_Rate.drop(df_Rate.iloc[0].index.name)
df_Rate = df_Rate.to_html()
# df_Rate = df_Rate.T
# df_Rate.columns = df_Rate.iloc[0]
# df_Rate = df_Rate.drop(df_Rate.iloc[0].index.name)
df_Rate = df_Rate.to_html(index=False)
@@ -139,7 +139,7 @@ def RateHistogram(DataRate, PhyType, SignalStrength, count):
figname="rate")
htmltable(" Encoding rate histogram.", df_Rate, str(path), "0", "0")
htmltable(" Encoding rate histogram.", df_Rate, str(path), "0", "0","Summary ")
# This is for Phy Histogram
@@ -156,16 +156,16 @@ def RateHistogram(DataRate, PhyType, SignalStrength, count):
for d in countUniquePhy:
perUniquePhy.append(round((d * 100) / count, 2))
df_Phy = pd.DataFrame({"Phy": [i for i in dictPhy.keys()], "Packet to Packet": [j for j in dictPhy.values()],"Percentage": [k for k in perUniquePhy]})
df_Phy = pd.DataFrame({" PHY ": [i for i in dictPhy.keys()], " Total Packets ": [j for j in dictPhy.values()]," Percentage ": [k for k in perUniquePhy]})
# print("df_Phy",df_Phy)
# df_Phy = df_Phy.to_html()
df_Phy = df_Phy.T
df_Phy.columns = df_Phy.iloc[0]
df_Phy = df_Phy.drop(df_Phy.iloc[0].index.name)
df_Phy = df_Phy.to_html()
# df_Phy = df_Phy.T
# df_Phy.columns = df_Phy.iloc[0]
# df_Phy = df_Phy.drop(df_Phy.iloc[0].index.name)
df_Phy = df_Phy.to_html(index=False)
dictphys = [i for i in dictPhy.keys()]
@@ -176,7 +176,7 @@ def RateHistogram(DataRate, PhyType, SignalStrength, count):
path = plot2.bar(datax=dictphys, datay=perUniquePhy, title="Phy plot", xaxis="Subtype", yaxis="Percentage",
figname="Phy")
htmltable(" Phy Histogram.",df_Phy,str(path),"0","0")
htmltable(" Phy Histogram.",df_Phy,str(path),"0","0","Summary ")
# This is for Signal Histogram
uniqueSignal = np.unique(SignalStrength)
@@ -199,38 +199,213 @@ def RateHistogram(DataRate, PhyType, SignalStrength, count):
# "Percentage": [k for k in perUniqueSignal]})
# pd.DataFrame.reset_index(drop=True,inplace=True)
print([k for k in dictSig.keys()])
print([i for i in dictSig.values()])
print("perUniqueSignal",perUniqueSignal)
# print([k for k in dictSig.keys()])
# print([i for i in dictSig.values()])
# print("perUniqueSignal",perUniqueSignal)
# pd.DataFrame
df_Sig = pd.DataFrame({"Signal":[k for k in dictSig.keys()],"Packet":[i for i in dictSig.values()],"Percentage":[j for j in perUniqueSignal]})
df_Sig = pd.DataFrame({" Signal ":[k for k in dictSig.keys()]," Total Packets ":[i for i in dictSig.values()]," Percentage ":[j for j in perUniqueSignal]})
df_Sig = df_Sig.T
df_Sig.columns = df_Sig.iloc[0]
df_Sig = df_Sig.drop(df_Sig.iloc[0].index.name)
# df_Sig = df_Sig.T
# df_Sig.columns = df_Sig.iloc[0]
# df_Sig = df_Sig.drop(df_Sig.iloc[0].index.name)
# df_Sig.columns.name = None
# df_Sig.index.name = "Signal"
print("df_Sig",df_Sig)
# print("df_Sig",df_Sig)
# print("df_Sig",df_Sig)
# df_Sig = df_Sig.to_html()
# df_Sig = df_Sig.transpose()
df_Sig = df_Sig.to_html()
df_Sig = df_Sig.to_html(index=False)
# perUniqueSignal.pop()
dictSigs = [i for i in dictSig.keys()]
# dictSigs.pop()
plot3 = Plot()
path = plot2.bar(datax=dictSigs, datay=perUniqueSignal, title="Signal plot", xaxis="Signal", yaxis="Percentage",
path = plot3.bar(datax=dictSigs, datay=perUniqueSignal, title="Signal plot", xaxis="Signal", yaxis="Percentage",
figname="Signal")
htmltable(" Signal Histogram.", df_Sig, str(path), "0", "0")
htmltable(" Signal Histogram.", df_Sig, str(path), "0", "0","Summary ")
# print(dictSigs,perUniqueSignal)
def PHY_BW_MCS_NCS(MCSIndex, vMCS, Bandwidth, vBW, PHY, vPHY, Spatial_Stream, vNCS, count):
countUniqueMCSIndex = []
countUniqueBandwidth = []
countUniquePHY = []
countUniqueSpatial_stream = []
perUniqueMCS = []
perUniqueBW = []
perUniquePHY = []
perUniqueNCS = []
uniqueMCSIndex = np.unique(MCSIndex)
uniqueBandwidth = ((np.unique(Bandwidth)))
# uniquePHY = ((np.unique(PHY)))
uniqueSpatial_stream = ((np.unique(Spatial_Stream)))
for countMCS in uniqueMCSIndex:
countUniqueMCSIndex.append(MCSIndex.count(countMCS))
for cnt in countUniqueMCSIndex:
perUniqueMCS.append(round((cnt * 100) / count, 2))
dictMCS = dict(zip(uniqueMCSIndex,countUniqueMCSIndex))
df_MCS = pd.DataFrame({" MCS ": [k for k in dictMCS.keys()], " Total Packets ": [i for i in dictMCS.values()]," Percentage ":[j for j in perUniqueMCS]})
# df_MCS = df_MCS.T
# df_MCS.columns = df_MCS.iloc[0]
# df_MCS = df_MCS.drop(df_MCS.iloc[0].index.name)
# print("df_MCS", df_MCS)
df_MCS = df_MCS.to_html(index=False)
dictMCSs = [i for i in dictMCS.keys()]
plot4 = Plot()
path = plot4.bar(datax=dictMCSs, datay=perUniqueMCS, title="MCS plot", xaxis="MCS", yaxis="Percentage",
figname="MCS")
PacketInfo = ("Data packets having MCS field: "+str(vMCS)+"<br>")
htmltable("Data MCS Histogram.", df_MCS, str(path), "0", "0",PacketInfo)
# print(uniqueMCSIndex, countUniqueMCSIndex)
for countBandwidth in uniqueBandwidth:
countUniqueBandwidth.append(Bandwidth.count(countBandwidth))
for cnt in countUniqueBandwidth:
perUniqueBW.append(round((cnt * 100) / count, 2))
dictBW = dict(zip(uniqueBandwidth, countUniqueBandwidth))
df_BW = pd.DataFrame({" Bandwidth ": [k for k in dictBW.keys()], " Total Packets ": [i for i in dictBW.values()]," Percentage ":[j for j in perUniqueBW]})
# df_BW = df_BW.T
# df_BW.columns = df_BW.iloc[0]
# df_BW = df_BW.drop(df_BW.iloc[0].index.name)
# print("df_BW", df_BW)
df_BW = df_BW.to_html(index=False)
dictBWs = [i for i in dictBW.keys()]
plot5 = Plot()
path = plot5.bar(datax=dictBWs, datay=perUniqueBW, title="Bandwidth plot", xaxis="Bandwidth", yaxis="Percentage",
figname="Bandwidth")
PacketInfo = ("Data packets having BW field: " + str(vBW) + "<br>")
htmltable("Data Bandwidth Histogram.", df_BW, str(path), "0", "0",PacketInfo)
# print(uniqueBandwidth, countUniqueBandwidth)
"""
#For PHY
for countPHY in uniquePHY:
countUniquePHY.append(PHY.count(countPHY))
for cnt in countUniquePHY:
perUniquePHY.append(round((cnt * 100) / count, 2))
dictPHY = dict(zip(uniquePHY, countUniquePHY))
df_PHY = pd.DataFrame({"PHY": [k for k in dictPHY.keys()], "Packet": [i for i in dictPHY.values()],"Percentage":[j for j in perUniquePHY]})
df_PHY = df_PHY.T
df_PHY.columns = df_PHY.iloc[0]
df_PHY = df_PHY.drop(df_PHY.iloc[0].index.name)
print("df_PHY", df_PHY)
"""
for countNCS in uniqueSpatial_stream:
countUniqueSpatial_stream.append(Spatial_Stream.count(countNCS))
for cnt in countUniqueSpatial_stream:
perUniqueNCS.append(round((cnt * 100) / count, 2))
dictNCS = dict(zip(uniqueSpatial_stream, countUniqueSpatial_stream))
df_NCS = pd.DataFrame({" NSS ": [k for k in dictNCS.keys()], " Total Packets ": [i for i in dictNCS.values()]," Percentage ":[j for j in perUniqueNCS]})
# df_NCS = df_NCS.T
# df_NCS.columns = df_NCS.iloc[0]
# df_NCS = df_NCS.drop(df_NCS.iloc[0].index.name)
# print("df_NCS", df_NCS)
# df_NCS = df_NCS.T
df_NCS = df_NCS.to_html(index=False)
dictNCSs = [i for i in dictNCS.keys()]
plot6 = Plot()
path = plot6.bar(datax=dictNCSs, datay=perUniqueNCS, title="NCS plot", xaxis="Spatial stream", yaxis="Percentage",
figname="NSS")
PacketInfo = ("Data packets having NSS field: " + str(vNCS) + "<br>")
htmltable("Data NSS Histogram.", df_NCS, str(path), "0", "0",PacketInfo)
def RateAMPDU(AMPDU,count):
countAMPDU = []
# print("IN AMPDU")
# print("AMPDU: ",AMPDU)
countUniqueAMPDU = []
perUniqueAMPDU = []
chainCountAMPDU = []
uniqueAMPDU = np.unique(AMPDU)
uniqueAMPDU = [i for i in uniqueAMPDU]
# print("uniqueAMPDU",uniqueAMPDU)
#
# print("len(uniqueAMPDU)",len(uniqueAMPDU))
for countAMPDU in uniqueAMPDU:
countUniqueAMPDU.append(AMPDU.count(countAMPDU))
# print("countUniqueAMPDU",countUniqueAMPDU)
# print("len(countUniqueAMPDU)",len(countUniqueAMPDU))
chainUniqueAMPDU = np.unique(countUniqueAMPDU)
chainUniqueAMPDU = [i for i in chainUniqueAMPDU]
# print("chainUniqueAMPDU", chainUniqueAMPDU)
# print("len(chainUniqueAMPDU)", len(chainUniqueAMPDU))
for Acount in chainUniqueAMPDU:
chainCountAMPDU.append(countUniqueAMPDU.count(Acount))
# print(" len(chainCountAMPDU): ", len(chainCountAMPDU))
# print("chainCountAMPDU",chainCountAMPDU)
UniqueChainCountAMPDU = np.unique(chainCountAMPDU)
UniqueChainCountAMPDU = [i for i in UniqueChainCountAMPDU]
listAMPDU = []
for un in UniqueChainCountAMPDU:
listAMPDU.append(chainCountAMPDU.count(un))
print(chainUniqueAMPDU,chainCountAMPDU)
dictAMPDU = dict(zip(chainUniqueAMPDU,chainCountAMPDU))
for acnt in chainCountAMPDU:
perUniqueAMPDU.append(round((acnt * 100) / count, 4))
#
# print("dictAMPDU",dictAMPDU)
#
# print("len(perUniqueAMPDU)",len(perUniqueAMPDU))
# print("perUniqueAMPDU",perUniqueAMPDU)
#
df_AMPDU = pd.DataFrame({" Chain count ": [k for k in dictAMPDU.keys()], " Total Packets ": [i for i in dictAMPDU.values()],
" Percentage ": [j for j in perUniqueAMPDU]})
# df_AMPDU = df_AMPDU.T
# df_AMPDU.columns = df_AMPDU.iloc[0]
# df_AMPDU = df_AMPDU.drop(df_AMPDU.iloc[0].index)
# df_AMPDU = df_AMPDU.T
df_AMPDU = df_AMPDU.to_html(index=False)
# dictAMPDUs = [i for i in dictAMPDU.keys()]
#
plot6 = Plot()
path = plot6.bar(datax=chainUniqueAMPDU, datay=perUniqueAMPDU, title="AMPDU plot", xaxis="packet Chain", yaxis="Percentage",
figname="AMPDU")
PacketInfo = ("EMPTY")
htmltable("AMPDU chain count Histogram.", df_AMPDU, str(path), "0", "0", PacketInfo)
class shark:
@@ -240,25 +415,27 @@ class shark:
# self.FilePath = "C:\Candela\Scripts\Lanforge scripts\lanforge-scripts-master\wifi_diag\wifi_diag.pcapng"
# self.FilePath = "wifi_diag.pcap"
# self.FilePath = "C:\candela\pcap\wifi.pcapng"
self.FilePath = "C:\candela\pcap\\ac1_28Sept.pcapng"
# self.FilePath = "C:\Candela\My_Scripts\WIFI_diag11ax\wifi.pcapng"
# self.FilePath = "wifi_diag.pcap"
# self.FilePath = "C:\candela\pcap\\ac_28Sept.pcapng"
# self.FilePath = "C:\candela\pcap\\11ax.pcapng"
# self.FilePath = "C:\candela\pcap\\11ax_cap2_Copy.pcapng"
# self.FilePath = "C:\candela\pcap\sta1.pcap"
self.FilePath = output
self.cap = pyshark.FileCapture(self.FilePath)
print("Strt time stamp :",datetime.datetime.now())
# print("Strt time stamp :",datetime.datetime.now())
def Extract(self):
type_list = {"0": "Management frame", "1": "Control Frame", "2": "Data frame"}
subtype_list = {"80": "Beacon frame", "d0": "Action", "b4": "Request-to-send", "d4": "Acknowledgement", \
"88": "QoS Data", "84": "Block Ack Req", "94": "Block Ack Req", "08": "Data", \
"88": "QoS Data", "84": "Block Ack Req", "94": "Block Ack Req", \
"40": "Probe Request", "50": "Probe Response", "b0": "Authentication",
"a2": "Disassociate", "a8": "QoS Data + CF-Poll", "c8":"QoS Null function", \
"10": "Association Response", "00": "Association Request", "c4": "Clear-to-send", \
"98": "QoS Data + CF-Acknowledgment", "24": "Trigger", "28": "Data + CF-Poll" ,\
"d8": "Unknown", "54": "VHT/HE NDP Announcement", "e8": "QoS CF-Poll", \
"b8" : "QoS Data + CF-Ack + CF-Poll", "18": "Data + CF-Ack", "48" : "Null function", \
"69" : "CF-Poll"
"69" : "CF-Poll", "08": "Data"
}
@@ -271,19 +448,12 @@ class shark:
MCSIndex = []
uniqueMCSIndex = []
countUniqueMCSIndex = []
MCSIndex
Bandwidth = []
countUniqueBandwidth = []
PHY = []
countUniquePHY = []
Spatial_Stream = []
countUniqueSpatial_stream = []
AMPDU = []
vDataType = 0
count = 0
vWLAN_RADIO = 0
vsignalstrength = 0
@@ -291,6 +461,16 @@ class shark:
vdatarate = 0
vWLAN = 0
vNotPHY = 0
vNotBW = 0
vNotMCS = 0
vNOTNCS = 0
vMCS = 0
vPHY = 0
vBW = 0
vNCS = 0
vAMPDU = 0
vNotAMPD = 0
""" Comment
"""
@@ -326,11 +506,21 @@ class shark:
for packet in self.cap:
count += 1
# print(count)
# print("Count :",end= " ")
print(count)
try:
WLAN_RADIO = packet.wlan_radio
wlan_radio_Fields_keys = []
wlan_radio_Fields_values = []
for keys, values in packet.wlan_radio._all_fields.items():
# print(keys, ":", values)
wlan_radio_Fields_keys.append(keys)
wlan_radio_Fields_values.append(values)
# print("---------------------------------------------")
vWLAN_RADIO = 1
try:
signalstrength = WLAN_RADIO.signal_dbm
@@ -356,12 +546,24 @@ class shark:
try:
RADIOTAP = packet.radiotap
# radiotap_field_keys = []
# radiotap_field_values = []
#
# for keys, values in packet.radiotap._all_fields.items():
# print(keys, ":", values)
# radiotap_field_keys.append(keys)
# radiotap_field_values.append(values)
# print("*****************RADIOTAP**************************")
except:
# print("RADIOTAP NOT FOUND")
pass
try:
WLAN = packet.wlan
# for keys, values in packet.wlan._all_fields.items():
# print(keys, ":", values)
# print("***********************************************")
vWLAN = 1
except:
pass
@@ -369,7 +571,6 @@ class shark:
PacketCount = (packet.number)
# print("PacketCount: ", PacketCount)
if vWLAN == 1:
@@ -396,8 +597,100 @@ class shark:
print("Control Frame", subtype, subtype_raw)
elif (type_raw == "2"):
try:
vDataType += 1
Data_framels.append(subtype_list[subtype_raw])
checkType = packet.wlan_radio._all_fields["wlan_radio.phy"]
try:
if "wlan_radio.11ac.bandwidth" and "wlan_radio.11ac.mcs" and "wlan_radio.11ac.nss" in wlan_radio_Fields_keys:
print("in 11ac")
try:
if "wlan_radio.11ac.bandwidth" in wlan_radio_Fields_keys:
Bandwidth.append(packet.wlan_radio._all_fields["wlan_radio.11ac.bandwidth"].showname_value)
vBW += 1
# print("11 ac bandwidth")
if "wlan_radio.11ac.mcs" in wlan_radio_Fields_keys:
MCSIndex.append(packet.wlan_radio._all_fields["wlan_radio.11ac.mcs"].showname_value)
vMCS += 1
# print("11 ac MCS")
if "wlan_radio.11ac.nss" in wlan_radio_Fields_keys:
Spatial_Stream.append(packet.wlan_radio._all_fields["wlan_radio.11ac.nss"].showname_value)
vNCS += 1
# print("11 ac NSS")
except:
print("wlan_radio.11ac.bandwidth or wlan_radio.11ac.mcs or wlan_radio.11ac.nss not found")
try:
# print("in 11ax")
radiotap_field_keys = []
radiotap_field_values = []
for keys, values in packet.radiotap._all_fields.items():
# print(keys, ":", values)
radiotap_field_keys.append(keys)
radiotap_field_values.append(values)
if "radiotap.he.data_3.data_mcs" and "radiotap.he.data_5.data_bw_ru_allocation" and "radiotap.he.data_6.nsts" in radiotap_field_keys:
print("in 11ax inside")
try:
if "radiotap.he.data_3.data_mcs" in radiotap_field_keys:
# print("in 11ax radiotap")
MCSIndex.append(packet.radiotap._all_fields["radiotap.he.data_3.data_mcs"].showname_value)
vMCS += 1
except:
print("MCS not found in ax")
try:
if "radiotap.he.data_5.data_bw_ru_allocation" in radiotap_field_keys:
# print("in BW radiotap 11ax")
Bandwidth.append(packet.radiotap._all_fields["radiotap.he.data_5.data_bw_ru_allocation"].showname_value)
vBW += 1
except:
print("BW not found in ax")
try:
if "radiotap.he.data_6.nsts" in radiotap_field_keys:
# print("in 11ax radiotap nsts")
Spatial_Stream.append(packet.radiotap._all_fields["radiotap.he.data_6.nsts"].showname_value)
vNCS += 1
except:
print("NSTS not found in ax")
except:
print("radiotap.he.data_3.data_mcs or radiotap.he.data_5.data_bw_ru_allocation or radiotap.he.data_6.nsts not found")
if "wlan_radio.a_mpdu_aggregate_id" in wlan_radio_Fields_keys:
AMPDU.append((packet.wlan_radio._all_fields["wlan_radio.a_mpdu_aggregate_id"].showname_value))
vAMPDU += 1
if "wlan_radio.phy" in wlan_radio_Fields_keys:
PHY.append(packet.wlan_radio._all_fields["wlan_radio.phy"].showname_value)
vPHY += 1
except:
pass
# print("comming out through try in except")
except:
print("Data frame", subtype, subtype_raw)
@@ -408,102 +701,117 @@ class shark:
print("Packet Number :",count,":"," WLAN NOT FOUND")
vWLAN = 0
if vWLAN_RADIO == 1:
# print("vWLAN Found")
if vdatarate == 1:
DataRate.append(datarate)
wlan_radio_Fields_keys = []
wlan_radio_Fields_values = []
if vPhy == 1:
PhyType.append(phy)
for keys, values in packet.wlan_radio._all_fields.items():
# print(keys, ":", values)
wlan_radio_Fields_keys.append(keys)
wlan_radio_Fields_values.append(values)
if vsignalstrength == 1:
SignalStrength.append(signalstrength)
if vdatarate == 1:
DataRate.append(datarate)
if vPhy == 1:
PhyType.append(phy)
if vsignalstrength == 1:
SignalStrength.append(signalstrength)
vWLAN_RADIO = 0
else:
print("Packet Number :",count," WLAN RADIO NOT FOUND")
try:
vMCS = 0
{"MCSIndex":['0 (BPSK 1/2)','1 (QPSK 1/2)','2 (QPSK 3/4)','4 (16-QAM 3/4)','5 (64-QAM 2/3)']}
{"Spatial_stream":["2"]}
{}
if "wlan_radio.11ac.bandwidth" and "wlan_radio.11ac.bandwidth" and "wlan_radio.phy" and \
"wlan_radio.11ac.mcs" and "wlan_radio.11ac.nss" in wlan_radio_Fields_keys:
print("\r"+count,":",packet.wlan_radio._all_fields.items())
# if "wlan_radio.11ac.bandwidth" and "wlan_radio.11ac.bandwidth" and "wlan_radio.phy" and \
# "wlan_radio.11ac.mcs" and "wlan_radio.11ac.nss" in wlan_radio_Fields_keys:
# print(dir(packet.wlan_radio._all_fields["wlan_radio.phy"]))
# print(packet.wlan_radio._all_fields["wlan_radio.phy"].showname_value) #for PHY
# print(packet.wlan_radio._all_fields["wlan_radio.11ac.bandwidth"].showname_value) #for BW
# print(packet.wlan_radio._all_fields["wlan_radio.11ac.mcs"].showname_value) #for MCS
# print(packet.wlan_radio._all_fields["wlan_radio.11ac.nss"].showname_value) #for Spatial streams
PHY.append(packet.wlan_radio._all_fields["wlan_radio.phy"].showname_value)
Bandwidth.append(packet.wlan_radio._all_fields["wlan_radio.11ac.bandwidth"].showname_value)
MCSIndex.append(packet.wlan_radio._all_fields["wlan_radio.11ac.mcs"].showname_value)
Spatial_Stream.append(packet.wlan_radio._all_fields["wlan_radio.11ac.nss"].showname_value)
vMCS = 1
# if "wlan_radio.phy" in wlan_radio_Fields_keys:
# PHY.append(packet.wlan_radio._all_fields["wlan_radio.phy"].showname_value)
# vPHY +=1
# else:
# vNotPHY +=1
# # print("PHY NF")
#
# if "wlan_radio.11ac.bandwidth" in wlan_radio_Fields_keys:
# Bandwidth.append(packet.wlan_radio._all_fields["wlan_radio.11ac.bandwidth"].showname_value)
# vBW +=1
# else:
# vNotBW += 1
# # print("Bandwidth NF")
#
# if "wlan_radio.11ac.mcs" in wlan_radio_Fields_keys:
# MCSIndex.append(packet.wlan_radio._all_fields["wlan_radio.11ac.mcs"].showname_value)
# vMCS +=1
# else:
# vNotMCS +=1
# # print("MCS Index NF")
#
# if "wlan_radio.11ac.nss" in wlan_radio_Fields_keys:
# Spatial_Stream.append(packet.wlan_radio._all_fields["wlan_radio.11ac.nss"].showname_value)
# vNCS += 1
# else:
# vNOTNCS += 1
# # print("Spatial stream NF")
except:
pass
# print("Here")
# print("MCSIndex",len(MCSIndex),MCSIndex)
# print("Bandwidth",len(Bandwidth),Bandwidth)
# print("PHY",len(PHY),PHY)
# print("Spatial_Stream",len(Spatial_Stream),Spatial_Stream)
if vAMPDU != 0:
RateAMPDU(AMPDU,count)
uniqueMCSIndex = np.unique(MCSIndex)
uniqueBandwidth = ((np.unique(Bandwidth)))
uniquePHY = ((np.unique(PHY)))
uniqueSpatial_stream = ((np.unique(Spatial_Stream)))
exit()
# print("Data Frames: ",vDataType)
print("After appending time stamp :", datetime.datetime.now())
# print(count)
# if vax11 == 1:
# print("vNOTNCS :", vNOTNCS, "vNotBW :", vNotBW, "vNotMCS:", vNotMCS, "vNotPHY:", vNotPHY)
# PHY_BW_MCS_NCS_11ax(MCSIndex, vMCS, vNotMCS, Bandwidth, vBW, vNotBW, PHY, vPHY, vNotPHY, count)
# else:
# print("vNotBW :",vNotBW,"vNotMCS:",vNotMCS,"vNotPHY:",vNotPHY)
PHY_BW_MCS_NCS(MCSIndex, vMCS, Bandwidth, vBW, PHY, vPHY, Spatial_Stream, vNCS, count)
# print("After appending time stamp :", datetime.datetime.now())
RateHistogram(DataRate, PhyType, SignalStrength, count)
print("After RateHist time stamp :", datetime.datetime.now())
# print("After RateHist time stamp :", datetime.datetime.now())
PacketHistogram(subtype_list, Managementls, Controlls, Data_framels, count)
print("After PacketHist time stamp :", datetime.datetime.now())
# print("After PacketHist time stamp :", datetime.datetime.now())
if __name__ == "__main__":
# parser = argparse.ArgumentParser(description="To create a single pcap file combining multiple pcap files")
# # parser.add_argument("-o", "--output", type=str, help="Enter the output pcap file name")
# parser.add_argument("-i", "--input", type=str,
# help="Enter the Name of the pcap files which needs to be combined")
#
# args = None
#
# try:
# args = parser.parse_args()
# output = "wifi_diag.pcap"
#
# if (args.input is not None):
# input = args.input # 'C:\candela\pcap\\11ax.pcapng','C:\candela\pcap\sta1.pcap'
# input = input.split(",")
# print(input)
#
# # if (args.input is None):
# # input = "11ax.pcapng", "sta1.pcap"
#
# except Exception as e:
# logging.exception(e)
# exit(2)
#
# with open(output, 'wb') as wfd:
# print("input", input)
# for f in (input):
# with open(f, 'rb') as fd:
# shutil.copyfileobj(fd, wfd)
parser = argparse.ArgumentParser(description="To create a single pcap file combining multiple pcap files")
# parser.add_argument("-o", "--output", type=str, help="Enter the output pcap file name")
parser.add_argument("-i", "--input", type=str,
help="Enter the Name of the pcap files which needs to be combined")
args = None
try:
args = parser.parse_args()
output = "wifi_diag.pcap"
if (args.input is not None):
input = args.input # 'C:\candela\pcap\\11ax.pcapng','C:\candela\pcap\sta1.pcap'
input = input.split(",")
print(input)
# if (args.input is None):
# input = "11ax.pcapng", "sta1.pcap"
except Exception as e:
logging.exception(e)
exit(2)
with open(output, 'wb') as wfd:
print("input", input)
for f in (input):
with open(f, 'rb') as fd:
shutil.copyfileobj(fd, wfd)
htmlstart()
downloadBtn()