user1036183
user1036183

Reputation: 333

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.

Upvotes: 0

Views: 3363

Answers (3)

bbum
bbum

Reputation: 162722

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. I.e. 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).

Upvotes: 1

Jef
Jef

Reputation: 2134

You need pdp_ip0 instead of en0.

Upvotes: 2

Simon Lee
Simon Lee

Reputation: 22334

Try looking for one of the other adapters, "en0" is the wifi card, try "en1"

Upvotes: 1

Related Questions