Radostin Stoyanov d84179e42f
clean up unused Python imports (#454)
* Remove unused python imports

These changes have been auto-generated with:

	pip3 install isort autoflake
	isort -rc -sl .
	autoflake --remove-all-unused-imports -i -r .
	isort -rc -m 3 .

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>

* python: remove redundant parenthesis

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2022-02-24 11:31:53 -05:00

28 lines
679 B
Python
Executable File

#!/usr/bin/env python3
from probe_hdrs import *
def expand(x):
yield x
while x.payload:
x = x.payload
yield x
def handle_pkt(pkt):
if ProbeData in pkt:
data_layers = [l for l in expand(pkt) if l.name=='ProbeData']
print("")
for sw in data_layers:
utilization = 0 if sw.cur_time == sw.last_time else 8.0*sw.byte_cnt/(sw.cur_time - sw.last_time)
print("Switch {} - Port {}: {} Mbps".format(sw.swid, sw.port, utilization))
def main():
iface = 'eth0'
print("sniffing on {}".format(iface))
sniff(iface = iface,
prn = lambda x: handle_pkt(x))
if __name__ == '__main__':
main()