iwinfo 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/ucode
  2. 'use strict';
  3. import * as iwinfo from 'iwinfo';
  4. function print_assoclist(stations) {
  5. for (let mac, station in stations) {
  6. printf(`${station.mac} ${station.signal} dBm / ${station.noise} dBm (SNR ${station.snr}) ${station.inactive_time} ms ago\n`);
  7. for (let k in [ 'rx', 'tx' ]) {
  8. let bitrate = station[k];
  9. let flags = join(', ', bitrate.flags);
  10. printf(`\t${uc(k)}: ${bitrate.bitrate} MBit/s`);
  11. if (length(bitrate.flags))
  12. printf(', %s', flags);
  13. printf('%10d Pkts.\n', bitrate.packets);
  14. }
  15. printf(`\texpected throughput: ${station.expected_throughput}\n\n`);
  16. }
  17. }
  18. function print_countrylist(list) {
  19. for (let k, v in list.countries)
  20. printf(`${k == list.active ? '*' : ' '} ${k} "${v}"\n`);
  21. }
  22. function print_freqlist(channels) {
  23. for (let channel in channels) {
  24. printf(`${channel.active ? '*' : ' '} ${channel.freq} GHz (Band: ${channel.band} GHz, Channel ${channel.channel})`);
  25. if (length(channel.flags))
  26. printf(` [${join(', ', channel.flags)}]`);
  27. printf('\n');
  28. }
  29. }
  30. function print_htmodelist(htmode) {
  31. printf('%s\n', join(' ', htmode));
  32. }
  33. function print_info(list) {
  34. let padding = ' ';
  35. for (let bss in list) {
  36. printf(`${bss.iface} ESSID: "${bss.ssid}"\n`);
  37. printf(`${padding}Access Point: ${bss.mac}\n`);
  38. printf(`${padding}Mode: ${bss.mode} Channel: ${bss.channel} (${bss.freq} GHz) HT Mode: ${bss.htmode}\n`);
  39. printf(`${padding}Center Channel 1: ${bss.center_freq1} 2: ${bss.center_freq2}\n`);
  40. printf(`${padding}Tx-Power: ${bss.txpower} dBm Link Quality: ${bss.quality}/70\n`);
  41. printf(`${padding}Signal: ${bss.signal} Noise: ${bss.noise}\n`);
  42. printf(`${padding}Bit Rate: ${bss.bitrate ?? 'unknown'} MBit/s\n`);
  43. printf(`${padding}Encryption: ${bss.encryption}\n`);
  44. printf(`${padding}Type: nl80211 HW Mode(s): 802.11${bss.hwmode}\n`);
  45. printf(`${padding}Hardware: ${bss.hw_type} [${bss.hw_id}]\n`);
  46. printf(`${padding}TX power offset: ${bss.power_offset}\n`);
  47. printf(`${padding}Channel offset: ${bss.channel_offset}\n`);
  48. printf(`${padding}Supports VAPs: ${bss.vaps} PHY name: ${bss.phy}\n`);
  49. if (bss.owe_transition_ifname)
  50. printf(`${padding}OWE partner: ${bss.owe_transition_ifname}\n`);
  51. printf('\n');
  52. }
  53. return 0;
  54. }
  55. function print_scan(cells) {
  56. let idx = 1;
  57. for (let cell in cells) {
  58. printf('Cell %02d - Address: %s\n', idx++, cell.bssid);
  59. printf('\t Mode: %s Frequency: %s GHz Band: %s GHz Channel: %d\n', cell.mode, cell.frequency, cell.band, cell.channel);
  60. printf('\t Signal: %d dBm Quality: %2d/70\n', cell.dbm, cell.quality);
  61. if (!length(cell.crypto.key_mgmt))
  62. printf('\t Encryption: NONE\n');
  63. else
  64. printf('\t Encryption: %s (%s)\n', join(' / ', cell.crypto.key_mgmt), join(' / ', cell.crypto.pair));
  65. if (cell.ht) {
  66. printf('\t HT Operation:\n');
  67. printf('\t\tPrimary Channel: %d\n', cell.ht.primary_channel);
  68. printf('\t\tSecondary Channel Offset: %s\n', cell.ht.secondary_chan_off);
  69. printf('\t\tChannel Width: %s\n', cell.ht.chan_width);
  70. }
  71. if (cell.vht) {
  72. printf('\t VHT Operation:\n');
  73. printf('\t\tCenter Frequency 1: %d\n', cell.vht.center_chan_1);
  74. printf('\t\tCenter Frequency 2: %s\n', cell.vht.center_chan_2);
  75. printf('\t\tChannel Width: %s\n', cell.vht.chan_width);
  76. }
  77. printf('\n');
  78. }
  79. }
  80. function print_txpowerlist(list) {
  81. for (let power in list)
  82. printf('%s %2d dbm (%4d mW)\n', power.active ? '*' : ' ', power.dbm, power.mw);
  83. }
  84. let pretty = true;
  85. if (ARGV[0] == '-j') {
  86. pretty = false;
  87. shift(ARGV);
  88. }
  89. if (!length(ARGV)) {
  90. let info = iwinfo.info();
  91. if (pretty)
  92. print_info(info);
  93. else
  94. printf('%.J\n', info);
  95. return 0;
  96. }
  97. const commands = {
  98. assoclist: [ iwinfo.assoclist, print_assoclist ],
  99. countrylist: [ iwinfo.countrylist, print_countrylist ],
  100. freqlist: [ iwinfo.freqlist, print_freqlist ],
  101. htmodelist: [ iwinfo.htmodelist, print_htmodelist ],
  102. info: [ iwinfo.info, print_info ],
  103. scan: [ iwinfo.scan, print_scan ],
  104. txpowerlist: [ iwinfo.txpowerlist, print_txpowerlist ],
  105. };
  106. if (length(ARGV) == 2 && iwinfo.ifaces[ARGV[0]])
  107. for (let cmd, cb in commands)
  108. if (substr(cmd, 0, length(ARGV[1])) == ARGV[1]) {
  109. let ret = cb[0](ARGV[0]);
  110. if (pretty)
  111. cb[1](ret);
  112. else
  113. printf('%.J\n', ret);
  114. return 0;
  115. }
  116. switch(ARGV[0]) {
  117. case 'phy':
  118. printf('%.J\n', iwinfo.phys);
  119. return 0;
  120. case 'iface':
  121. printf('%.J\n', iwinfo.ifaces);
  122. return 0;
  123. }
  124. printf('Usage:\n' +
  125. '\tiwinfo <device> info\n' +
  126. '\tiwinfo <device> scan\n' +
  127. '\tiwinfo <device> txpowerlist\n' +
  128. '\tiwinfo <device> freqlist\n' +
  129. '\tiwinfo <device> assoclist\n' +
  130. '\tiwinfo <device> countrylist\n' +
  131. '\tiwinfo <device> htmodelist\n' +
  132. '\tiwinfo <backend> phyname <section>\n');