Skip to content

Instantly share code, notes, and snippets.

@loderunner
Created November 25, 2014 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loderunner/e6ef7eca1b41c22d0ac9 to your computer and use it in GitHub Desktop.
Save loderunner/e6ef7eca1b41c22d0ac9 to your computer and use it in GitHub Desktop.
QApplication qapp(argc, argv);
{
QNetworkConfigurationManager manager;
QList<QNetworkConfiguration> configs(manager.allConfigurations());
QNetworkConfiguration config;
foreach (config, configs)
{
NSString* type;
switch (config.type())
{
case QNetworkConfiguration::InternetAccessPoint:
type = @"InternetAccessPoint";
break;
case QNetworkConfiguration::ServiceNetwork:
type = @"ServiceNetwork";
break;
case QNetworkConfiguration::UserChoice:
type = @"UserChoice";
break;
case QNetworkConfiguration::Invalid:
type = @"Invalid";
break;
}
NSString* state;
switch (config.state())
{
case QNetworkConfiguration::Undefined:
state = @"Undefined";
break;
case QNetworkConfiguration::Defined:
state = @"Defined";
break;
case QNetworkConfiguration::Discovered:
state = @"Discovered";
break;
case QNetworkConfiguration::Active:
state = @"Active";
break;
}
NSString* purpose;
switch (config.purpose())
{
case QNetworkConfiguration::UnknownPurpose:
purpose = @"UnknownPurpose";
break;
case QNetworkConfiguration::PublicPurpose:
purpose = @"PublicPurpose";
break;
case QNetworkConfiguration::PrivatePurpose:
purpose = @"PrivatePurpose";
break;
case QNetworkConfiguration::ServiceSpecificPurpose:
purpose = @"ServiceSpecificPurpose";
break;
}
NSLog(@"%@ (%@): bearer: %@, type: %@, state: %@, purpose: %@)",
config.name().toNSString(),
config.identifier().toNSString(),
config.bearerTypeName().toNSString(),
type,
state,
purpose);
}
}
NSLog(@"********************************************************");
{
QList<QHostAddress> addresses(QNetworkInterface::allAddresses());
foreach(QHostAddress host, addresses)
{
NSLog(@"%@", host.toString().toNSString());
}
}
NSLog(@"********************************************************");
{
QList<QNetworkInterface> interfaces(QNetworkInterface::allInterfaces());
foreach(QNetworkInterface interface, interfaces)
{
QNetworkInterface::InterfaceFlags flags = interface.flags();
NSMutableArray* options = [NSMutableArray array];
if (flags & QNetworkInterface::IsUp) [options addObject:@"up"];
if (flags & QNetworkInterface::IsRunning) [options addObject:@"running"];
if (flags & QNetworkInterface::CanBroadcast) [options addObject:@"broadcast"];
if (flags & QNetworkInterface::IsLoopBack) [options addObject:@"loopback"];
if (flags & QNetworkInterface::IsPointToPoint) [options addObject:@"point-to-point"];
if (flags & QNetworkInterface::CanMulticast) [options addObject:@"multicast"];
NSLog(@"%@: name: %@, valid: %@, flags: %@",
interface.humanReadableName().toNSString(),
interface.name().toNSString(),
interface.isValid() ? @"YES" : @"NO",
[options componentsJoinedByString:@" | "]);
}
}
NSLog(@"********************************************************");
{
for (NSString* addr in @[@"127.0.0.1", @"127.0.0.100", @"8.8.8.8", @"1.2.3.4", @"173.194.45.69", @"0.0.0.0", @"255.255.255.255"])
{
QHostAddress host(QString::fromNSString(addr));
QUdpSocket udpSocket;
qint64 res = udpSocket.writeDatagram("", 0, host, 5000);
NSLog(@"%@: %@", addr, @(res));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment