如何以编程方式获取我的P2P远程主机的IP地址

问题描述 投票:0回答:1

我正在使用以下方式以编程方式将我的iOS设备连接到特定的WiFi网络。这在用户许可的情况下效果很好!

NSString* str_wifi_ssid = "WiFI_SSID_Name";
NSString* str_password = "SecretPass";

NEHotspotConfiguration *configuration = [[NEHotspotConfiguration alloc] initWithSSID:str_wifi_ssid passphrase:str_password isWEP: false];

[[NEHotspotConfigurationManager sharedManager] applyConfiguration: configuration completionHandler: ^ (NSError * _Nullable error) {
    if (nil == error) {
        // Connected to desired WiFi!; How can I get the remote host's IP address here ?
    }}];

问题:我想获取我的主机IP地址,该地址应该类似于192.168.1.1。如何以编程方式获取该信息?或者换句话说,如何获得我的P2P远程主机的IP地址?

我正在运行iOS 13.3.1

对于解决方案是在objective-c,C ++或C中对我来说都没关系。

ios objective-c
1个回答
0
投票

[不确定是否需要尝试以下操作(尽管它可能很懒并且需要打开某些连接,所以只需使用URLSession发送任何http请求,或使用NWTCPConnection从相同的NetworkExtension.framework打开tcp连接

NEIPv4Route *route = [NEIPv4Route defaultRoute];

NSString *destination = route.destinationAddress;
NSString *gateway = route.gatewayAddress; // << guess you wanted this one
© www.soinside.com 2019 - 2024. All rights reserved.