简体   繁体   中英

Current IP address of phone, whether connected via WiFi or 3G

I need to create a function that returns the current IP address of the phone.

I found this (but it is only for when the phone is conntected to the WiFi -- I need the address even if it is connected via 3G) http://blog.zachwaugh.com/post/309927273/programmatically-retrieving-ip-address-of-iphone

Further, once I have the IP address, I'd like to find the country that it's from.

您需要pdp_ip0而不是en0

尝试寻找其他适配器之一,“ en0”是无线网卡,尝试“ en1”

Mapping IP address -> country isn't going to work. Specifically, if the phone is connected to any consumer WiFi base station, it is almost guaranteed that said base station is using NAT (network address translation) to share a single IP amongst connected devices. Ie you'll see IP addresses that start with 10.0.##.## or 192.168.1.## .

You have to contact an external server to figure out what IP address your device is potentially hiding behind.

Lots of info here (though I know nothing about the company running this).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM