Debian Codegraph @

examples/info.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """ info.py
3 Copyright (C) 2016 Dale V. Patterson ([email protected])
4
5 This program is free software: you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation, either version 3 of the License, or (at your option) any later
8 version.
9
10 Redistribution and use in source and binary forms, with or without
11 modifications, are permitted provided that the following conditions are met:
12 o Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
14 o Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 o Neither the name of the orginal author Dale V. Patterson nor the names of
18 any contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20
21 Example for displaying device details
22
23 """
24
25 from __future__ import print_function # python 2to3 compability
26 import argparse as ap # cli arg parsing
27 import sys # cli exiting
28 import pyric # pyric error (and ecode EUNDEF)
29 import pyric.pyw as pyw # for iw functionality
30 from pyric.utils.channels import rf2ch # rf to channel conversion
31
32 def execute(dev,itype):
33 # ensure dev is a wireless interfaces
34 wifaces = pyw.winterfaces()
35 if dev not in wifaces:
36 print("Device {0} is not wireless, use one of {1}".format(dev,wifaces))
37
38 # get info dicts
39 dinfo = pyw.devinfo(dev)
40 card = dinfo['card']
41 pinfo = pyw.phyinfo(card)
42 iinfo = pyw.ifinfo(card)
43
44 if itype == 'all' or itype == 'if':
45 msg = "Interface {0}\n".format(card.idx)
46 msg += "\tDriver: {0} Chipset: {1}\n".format(iinfo['driver'],iinfo['chipset'])
47 msg += "\tHW Addr: {0} Manufacturer: {1}\n".format(iinfo['hwaddr'],
48 iinfo['manufacturer'])
49 msg += "\tInet: {0} Bcast: {1} Mask: {2}\n".format(iinfo['inet'],
50 iinfo['bcast'],
51 iinfo['mask'])
52 print(msg)
53
54 if itype == 'all' or itype == 'dev':
55 msg = "Device {0}\n".format(card.dev)
56 msg += "\tifindex: {0}\n".format(card.idx)
57 msg += "\twdev: {0}\n".format(dinfo['wdev'])
58 msg += "\taddr: {0}\n".format(dinfo['mac'])
59 msg += "\tmode: {0}\n".format(dinfo['mode'])
60 msg += "\twiphy: {0}\n".format(card.phy)
61 if dinfo['mode'] != 'managed': msg += "\tDevice not associated\n"
62 else:
63 msg += "\tchannel: {0} ({1} MHz), width: {2}, CF: {3} MHz\n".format(rf2ch(dinfo['RF']),
64 dinfo['RF'],
65 dinfo['CHW'],
66 dinfo['CF'])
67 print(msg)
68
69 if itype == 'all' or itype == 'phy':
70 msg = "Wiphy phy{0}\n".format(card.phy)
71 msg += "\tGeneration: {0}m Coverage Class: {1}\n".format(pinfo['generation'],
72 pinfo['cov_class'])
73 msg += "\tMax # scan SSIDs: {0}\n".format(pinfo['scan_ssids'])
74 msg += "\tRetry Short: {0}, Long: {1}\n".format(pinfo['retry_short'],
75 pinfo['retry_long'])
76 msg += "\tThreshold Frag: {0}, RTS: {1}\n".format(pinfo['frag_thresh'],
77 pinfo['rts_thresh'])
78 msg += "\tSupported Modes:\n"
79 for mode in pinfo['modes']: msg += "\t * {0}\n".format(mode)
80 msg += "\tSupported Commands:\n"
81 for cmd in pinfo['commands']: msg += "\t * {0}\n".format(cmd)
82 msg += "\tSupported Ciphers:\n"
83 for cipher in pinfo['ciphers']: msg += "\t * {0}\n".format(cipher)
84 for band in pinfo['bands']:
85 msg += "\tBand {0}: (HT: {1} VHT: {2})\n".format(band,
86 pinfo['bands'][band]['HT'],
87 pinfo['bands'][band]['VHT'])
88 msg += "\t Rates:\n"
89 for rate in pinfo['bands'][band]['rates']:
90 msg += "\t * {0} Mbps\n".format(rate)
91 msg += "\t Frequencies:\n"
92 for i,rf in enumerate(pinfo['bands'][band]['rfs']):
93 dbm = pinfo['bands'][band]['rf-data'][i]['max-tx']
94 msg += "\t * {0} MHz ({1} dBm)".format(rf,dbm)
95 if not pinfo['bands'][band]['rf-data'][i]['enabled']:
96 msg += " (disabled)\n"
97 else:
98 msg += "\n"
99 print(msg)
100
101 if __name__ == '__main__':
102 # create arg parser and parse command line args
103 print("Wireless Device Info Display using PyRIC v{0}".format(pyric.version))
104 argp = ap.ArgumentParser(description="Wireless Device Data")
105 argp.add_argument('-d','--dev',help="Wireless Device")
106 argp.add_argument('-t','--type',help="Info type one of {all|if|dev|phy}")
107 args = argp.parse_args()
108 usage = "usage: python info.py -d <dev> [-t one of {all|if|dev|phy}]"
109 try:
110 dname = args.dev
111 infotype = args.type
112 if dname is None:
113 print(usage)
114 sys.exit(0)
115 if infotype is None: infotype = 'all'
116 if infotype not in ['all','if','dev','phy']:
117 print(usage)
118 sys.exit(0)
119 execute(dname,infotype)
120 except pyric.error as e:
121 print(e)