#include #include #include #include #include "interface.h" #include "neighbor.h" #include "wireless.h" int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); Interface interface("enp0s3"); Neighbor neighbor; bool neighOk = false; std::cout << "MAC: " << qPrintable(neighbor.macOfIP("10.0.4.1")) << std::endl; QStringList addresses = interface.addresses(); foreach(QString address, addresses) { std::cout << "Address: " << qPrintable(address) << std::endl; } std::cout << "Link of " << qPrintable(interface.name()) << " is: " << interface.hasCarrier() << std::endl; std::cout << "Interfaces:" << std::endl; QStringList links = Interface::list(); foreach(QString link, links) { std::cout << qPrintable(link) << std::endl; } std::cout << "-----" << std::endl; std::cout << "Neighbors:" << std::endl; QHash neighs = Neighbor::list("", &neighOk); std::cout << (neighOk ? "(ok)" : "(not ok)") << std::endl; foreach(QString neigh, neighs.keys()) { std::cout << qPrintable(neigh) << " (" << qPrintable(neighs.value(neigh)) << ")" << std::endl; } std::cout << "-----" << std::endl; //interface.deleteAddress("1.1.1.5/29"); Wireless wi("wlp0s11u1"); QList bands = wi.bandMap(); foreach(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)" : ""); if((band.width & Wireless::WIDTH_20MHZ) == Wireless::WIDTH_20MHZ) { std::cout << " (20MHz)"; } if((band.width & Wireless::WIDTH_40MHZ) == Wireless::WIDTH_40MHZ) { std::cout << " (40MHz)"; } std::cout << std::endl; if(band.channels.count() > 0) { foreach(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:"; foreach(int chan, wi.allChannels()) { std::cout << " " << chan; } std::cout << std::endl; //// std::cout << "allowed TX/RX channels:"; foreach(int chan, wi.allowedChannels(Wireless::Direction_Both)) { std::cout << " " << chan; } std::cout << std::endl; //// std::cout << "allowed RX channels:"; foreach(int chan, wi.allowedChannels(Wireless::Direction_RX)) { std::cout << " " << chan; } std::cout << std::endl; //// std::cout << "all frequencies:"; foreach(int freq, wi.allFrequencies()) { std::cout << " " << freq; } std::cout << std::endl; QTimer::singleShot(0, qApp, SLOT(quit())); int ret = app.exec(); return ret; }