mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 11:18:03 +00:00
added lf_sniff_radio and set_wifi_radio options
This commit is contained in:
17
py-json/LANforge/set_wifi_radio.py
Normal file
17
py-json/LANforge/set_wifi_radio.py
Normal file
@@ -0,0 +1,17 @@
|
||||
set_radio_mode = {
|
||||
"AUTO": 0,
|
||||
"802.11a": 1, # 802.11a
|
||||
"802.11b": 2, # 802.11b
|
||||
"802.11g": 3, # 802.11g
|
||||
"802.11abg": 4, # 802.11abg
|
||||
"802.11abgn": 5, # 802.11abgn
|
||||
"802.11bgn": 6, # 802.11bgn
|
||||
"802.11bg": 7, # 802.11bg
|
||||
"802.11abgnAC": 8, # 802.11abgn-AC
|
||||
"802.11anAC": 9, # 802.11an-AC
|
||||
"802.11an": 10, # 802.11an
|
||||
"802.11bgnAC": 11, # 802.11bgn-AC
|
||||
"802.11abgnAX": 12, # 802.11abgn-AX a/b/g/n/AC/AX (dual-band AX) support
|
||||
"802.11bgnAX": 13, # 802.11bgn-AX
|
||||
"802.11anAX": 14 # 802.11an-AX
|
||||
}
|
||||
@@ -6,7 +6,7 @@ from LANforge import LFUtils
|
||||
import pprint
|
||||
from pprint import pprint
|
||||
import time
|
||||
|
||||
from LANforge.set_wifi_radio import set_radio_mode
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class WifiMonitor:
|
||||
self.aid = "NA" # used when sniffing /ax radios
|
||||
self.bsssid = "00:00:00:00:00:00" # used when sniffing on /ax radios
|
||||
|
||||
def create(self, resource_=1, channel=None, radio_="wiphy0", name_="moni0"):
|
||||
def create(self, resource_=1, channel=None, mode="AUTO", radio_="wiphy0", name_="moni0"):
|
||||
print("Creating monitor " + name_)
|
||||
self.monitor_name = name_
|
||||
computed_flags = 0
|
||||
@@ -50,10 +50,11 @@ class WifiMonitor:
|
||||
"shelf": 1,
|
||||
"resource": resource_,
|
||||
"radio": radio_,
|
||||
"mode": 0, # "NA", #0 for AUTO or "NA"
|
||||
"mode": set_radio_mode[mode], # "NA", #0 for AUTO or "NA"
|
||||
"channel": channel,
|
||||
"country": country,
|
||||
"frequency": self.local_realm.channel_freq(channel_=channel)
|
||||
|
||||
}
|
||||
self.local_realm.json_post("/cli-json/set_wifi_radio", _data=data)
|
||||
time.sleep(1)
|
||||
@@ -107,6 +108,7 @@ class WifiMonitor:
|
||||
def admin_up(self):
|
||||
up_request = LFUtils.port_up_request(resource_id=self.resource, port_name=self.monitor_name)
|
||||
self.local_realm.json_post("/cli-json/set_port", up_request)
|
||||
self.local_realm.json_post("/cli-json/set_port", up_request)
|
||||
|
||||
def admin_down(self):
|
||||
down_request = LFUtils.portDownRequest(resource_id=self.resource, port_name=self.monitor_name)
|
||||
|
||||
107
py-scripts/lf_sniff_radio.py
Normal file
107
py-scripts/lf_sniff_radio.py
Normal file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
NAME: lf_sniff_radio.py
|
||||
PURPOSE: THis script will sniff a Radio after changing the Radio settings.
|
||||
|
||||
Radio settings: channel radio mode AUTO, 802.11a, 802.11b, etc... refer
|
||||
lanforge-scripts/py-json/LANforge/set_wifi_radio.py for different modes
|
||||
|
||||
EXAMPLE: python3 lf_sniff_radio.py
|
||||
--mgr localhost
|
||||
--mgr_port 8080
|
||||
--outfile /home/lanforge/test_sniff.pcap
|
||||
--duration 20
|
||||
--channel 52
|
||||
--radio_mode AUTO
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
if 'py-json' not in sys.path:
|
||||
sys.path.append('../py-json')
|
||||
|
||||
import argparse
|
||||
import time
|
||||
from LANforge.LFUtils import *
|
||||
from realm import Realm
|
||||
|
||||
|
||||
class SniffRadio(Realm):
|
||||
def __init__(self,
|
||||
lfclient_host="localhost",
|
||||
lfclient_port=8080,
|
||||
radio="wiphy0",
|
||||
outfile="/home/lanforge/test_pcap.pcap",
|
||||
duration=60,
|
||||
channel=52,
|
||||
radio_mode="AUTO"):
|
||||
super().__init__(lfclient_host, lfclient_port)
|
||||
self.monitor = self.new_wifi_monitor_profile()
|
||||
if channel != "AUTO":
|
||||
channel = int(channel)
|
||||
self.channel = channel
|
||||
self.duration = duration
|
||||
self.outfile = outfile
|
||||
self.mode = radio_mode
|
||||
self.radio = radio
|
||||
|
||||
def setup(self):
|
||||
self.monitor.create(radio_=self.radio, channel=self.channel, mode=self.mode, name_="moni3a")
|
||||
|
||||
def start(self):
|
||||
self.monitor.admin_up()
|
||||
time.sleep(5)
|
||||
self.monitor.start_sniff(capname=self.outfile, duration_sec=self.duration)
|
||||
for i in range(0, self.duration):
|
||||
print("started sniffer, PLease wait,", self.duration - i)
|
||||
time.sleep(1)
|
||||
print("Sniffing Completed Success", "Check ", self.outfile)
|
||||
self.monitor.admin_down()
|
||||
time.sleep(2)
|
||||
|
||||
def cleanup(self):
|
||||
self.monitor.cleanup()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(usage=
|
||||
"""./lf_sniff_radio.py
|
||||
--mgr localhost
|
||||
--mgr_port 8080
|
||||
--radio wiphy0
|
||||
--outfile /home/lanforge/test_sniff.pcap
|
||||
--duration 1
|
||||
--channel 52
|
||||
--radio_mode AUTO
|
||||
""")
|
||||
|
||||
parser.add_argument('--mgr', type=str, help='--mgr: IP Address of LANforge', default="localhost")
|
||||
parser.add_argument('--mgr_port', type=int, help='--mgr_port: HTTP Port of LANforge', default=8080)
|
||||
parser.add_argument('--radio', type=str, help='--radio: Radio to sniff', default="wiphy0")
|
||||
parser.add_argument('--outfile', type=str, help='--outfile: give the filename with path',
|
||||
default="/home/lanforge/test_pcap.pcap")
|
||||
parser.add_argument('--duration', type=int, help='--duration duration in sec, for which you want to capture',
|
||||
default=60)
|
||||
parser.add_argument('--channel', type=str, help='--channel Set channel pn selected Radio, [52, 56 ...]',
|
||||
default=0)
|
||||
parser.add_argument('--radio_mode', type=str, help='--radio_mode select the radio mode [AUTO, 802.11a, 802.11b, '
|
||||
'802.11ab ...]', default="AUTO")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
obj = SniffRadio(lfclient_host=args.mgr,
|
||||
lfclient_port=args.mgr_port,
|
||||
outfile=args.outfile,
|
||||
duration=args.duration,
|
||||
channel=args.channel,
|
||||
radio_mode=args.radio_mode
|
||||
)
|
||||
obj.setup()
|
||||
time.sleep(5)
|
||||
obj.start()
|
||||
obj.cleanup()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user