From 6f0d941de10a5b587c719498f8e9884b2c1a2b66 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Mon, 5 May 2014 18:02:57 -0400 Subject: [PATCH] show all wifi interfaces --- iptest/iptest.cpp | 126 ++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/iptest/iptest.cpp b/iptest/iptest.cpp index f53375c..6f84499 100644 --- a/iptest/iptest.cpp +++ b/iptest/iptest.cpp @@ -41,93 +41,97 @@ int main(int argc, char *argv[]) { std::cout << qPrintable(neigh) << " (" << qPrintable(neighs.value(neigh)) << ")" << std::endl; } - std::cout << "-----" << std::endl; - - //interface.deleteAddress("1.1.1.5/29"); + QStringList wifiInterfaces = Wireless::interfaceList(); - Wireless wi("wlp0s29u1u2"); + foreach(QString wifi, wifiInterfaces) { + std::cout << "----- " << qPrintable(wifi) << std::endl; - QList bands = wi.bandMap(); + //interface.deleteAddress("1.1.1.5/29"); - foreach(Wireless::BandInfo band, bands) { - std::cout << "found band" << - (((band.band & Wireless::BAND_2GHZ) == Wireless::BAND_2GHZ) ? " 2GHz" : "") << - (((band.band & Wireless::BAND_5GHZ) == Wireless::BAND_5GHZ) ? " 5GHz" : "") << - (((band.protocols & Wireless::PROTOCOL_80211_A) == Wireless::PROTOCOL_80211_A) ? " (802.11a)" : "") << - (((band.protocols & Wireless::PROTOCOL_80211_B) == Wireless::PROTOCOL_80211_B) ? " (802.11b)" : "") << - (((band.protocols & Wireless::PROTOCOL_80211_G) == Wireless::PROTOCOL_80211_G) ? " (802.11g)" : "") << - (((band.protocols & Wireless::PROTOCOL_80211_N) == Wireless::PROTOCOL_80211_N) ? " (802.11n)" : ""); + Wireless wi(wifi); - if((band.width & Wireless::WIDTH_20MHZ) == Wireless::WIDTH_20MHZ) { - std::cout << " (20MHz)"; - } + QList bands = wi.bandMap(); - if((band.width & Wireless::WIDTH_40MHZ) == Wireless::WIDTH_40MHZ) { - std::cout << " (40MHz)"; - } + foreach(Wireless::BandInfo band, bands) { + std::cout << "found band" << + (((band.band & Wireless::BAND_2GHZ) == Wireless::BAND_2GHZ) ? " 2GHz" : "") << + (((band.band & Wireless::BAND_5GHZ) == Wireless::BAND_5GHZ) ? " 5GHz" : "") << + (((band.protocols & Wireless::PROTOCOL_80211_A) == Wireless::PROTOCOL_80211_A) ? " (802.11a)" : "") << + (((band.protocols & Wireless::PROTOCOL_80211_B) == Wireless::PROTOCOL_80211_B) ? " (802.11b)" : "") << + (((band.protocols & Wireless::PROTOCOL_80211_G) == Wireless::PROTOCOL_80211_G) ? " (802.11g)" : "") << + (((band.protocols & Wireless::PROTOCOL_80211_N) == Wireless::PROTOCOL_80211_N) ? " (802.11n)" : ""); - std::cout << std::endl; + if((band.width & Wireless::WIDTH_20MHZ) == Wireless::WIDTH_20MHZ) { + std::cout << " (20MHz)"; + } - if(band.channels.count() > 0) { - foreach(Wireless::ChannelInfo info, band.channels) { - std::cout << " found channel " << info.chan << " (" << info.freq << "): " << - "Disabled?: " << (info.disabled ? "yes" : "no") << " " << - "Passive?: " << (info.passive ? "yes" : "no") << " " << - "Radar?: " << (info.radar ? "yes" : "no") << " " << - "Max TX Power: " << info.max_txpower << " " << - std::endl; + if((band.width & Wireless::WIDTH_40MHZ) == Wireless::WIDTH_40MHZ) { + std::cout << " (40MHz)"; } - std::cout << "converting channel 1 to freq: " << qPrintable(Wireless::ChanToFreq("Channel: 1")) << std::endl; - std::cout << "converting freq 5200 to channel: " << qPrintable(Wireless::FreqToChan("Frequency: 5.2GHz")) << std::endl; - std::cout << "is channel 11 supported? " << (wi.channelSupported(11) ? "yes" : "no") << std::endl; - std::cout << "is channel 165 supported? " << (wi.channelSupported(165) ? "yes" : "no") << std::endl; - std::cout << "is frequency 2.437GHz supported? " << (wi.frequencySupported(2437) ? "yes" : "no") << std::endl; - std::cout << "is frequency 5.825GHz supported? " << (wi.frequencySupported(5825) ? "yes" : "no") << std::endl; - }else{ - std::cout << "no channels supported" << std::endl; + std::cout << std::endl; + + if(band.channels.count() > 0) { + foreach(Wireless::ChannelInfo info, band.channels) { + std::cout << " found channel " << info.chan << " (" << info.freq << "): " << + "Disabled?: " << (info.disabled ? "yes" : "no") << " " << + "Passive?: " << (info.passive ? "yes" : "no") << " " << + "Radar?: " << (info.radar ? "yes" : "no") << " " << + "Max TX Power: " << info.max_txpower << " " << + std::endl; + } + + std::cout << "converting channel 1 to freq: " << qPrintable(Wireless::ChanToFreq("Channel: 1")) << std::endl; + std::cout << "converting freq 5200 to channel: " << qPrintable(Wireless::FreqToChan("Frequency: 5.2GHz")) << std::endl; + std::cout << "is channel 11 supported? " << (wi.channelSupported(11) ? "yes" : "no") << std::endl; + std::cout << "is channel 165 supported? " << (wi.channelSupported(165) ? "yes" : "no") << std::endl; + std::cout << "is frequency 2.437GHz supported? " << (wi.frequencySupported(2437) ? "yes" : "no") << std::endl; + std::cout << "is frequency 5.825GHz supported? " << (wi.frequencySupported(5825) ? "yes" : "no") << std::endl; + }else{ + std::cout << "no channels supported" << std::endl; + } } - } - std::cout << "all channels:"; + std::cout << "all channels:"; - foreach(int chan, wi.allChannels()) { - std::cout << " " << chan; - } + foreach(int chan, wi.allChannels()) { + std::cout << " " << chan; + } - std::cout << std::endl; + std::cout << std::endl; - //// + //// - std::cout << "allowed TX/RX channels:"; + std::cout << "allowed TX/RX channels:"; - foreach(int chan, wi.allowedChannels(Wireless::Direction_Both)) { - std::cout << " " << chan; - } + foreach(int chan, wi.allowedChannels(Wireless::Direction_Both)) { + std::cout << " " << chan; + } - std::cout << std::endl; + std::cout << std::endl; - //// + //// - std::cout << "allowed RX channels:"; + std::cout << "allowed RX channels:"; - foreach(int chan, wi.allowedChannels(Wireless::Direction_RX)) { - std::cout << " " << chan; - } + foreach(int chan, wi.allowedChannels(Wireless::Direction_RX)) { + std::cout << " " << chan; + } - std::cout << std::endl; + std::cout << std::endl; - //// + //// - std::cout << "all frequencies:"; + std::cout << "all frequencies:"; - foreach(int freq, wi.allFrequencies()) { - std::cout << " " << freq; - } + foreach(int freq, wi.allFrequencies()) { + std::cout << " " << freq; + } - std::cout << std::endl; + std::cout << std::endl; - std::cout << "wifi interface type: " << qPrintable(wi.getInterfaceType()) << std::endl; + std::cout << "wifi interface type: " << qPrintable(wi.getInterfaceType()) << std::endl; + } QTimer::singleShot(0, qApp, SLOT(quit()));