首页 文章

iOS:路由器IP可达?

提问于
浏览
1

我想在我的iPhone应用程序中检查互联网连接 .

The app needs to know, if the phone is connected via wifi and if wifi is connected with the strict router.

例如:这是一个在酒吧订购饮料的应用程序 . 如果用户连接到栏的网络,则仅允许用户订购 .

我试过了:

- (IBAction)buttonCHECKNETWORK:(id)sender{

struct sockaddr_in callAddress;
callAddress.sin_len = sizeof(callAddress);
callAddress.sin_family = AF_INET;
callAddress.sin_port = htons(24);
callAddress.sin_addr.s_addr = inet_addr("152.465.456.975");

 Reachability *hostReach = [Reachability reachabilityWithAddress:&callAddress];

NetworkStatus netStatus = [hostReach currentReachabilityStatus];

if (netStatus == NotReachable)
{
    NSLog(@"IP NotReachable");
}

if (netStatus == ReachableViaWiFi)
{
    NSLog(@"IP ReachableViaWiFi");
}

if (netStatus == ReachableViaWWAN)
{
    NSLog(@"IP ReachableViaWWAN");
} }

但是每个IP都可以访问(在我的代码中也是这个虚构的IP)......我想将Router IP放在'callAddress'中 . 或路由器的名称或类似的东西..如果用户通过3G连接将无法访问 .

1 回答

  • 1

    通过获取本地IP地址(例如,请参阅iPhone Obtaining IP Address When Connected Over 3G - 并注意此解决方案也提供了Wi-Fi地址),您可以将其与条形码路由器的固定IP地址范围进行比较,看看您是否在同一网络中 .

相关问题