0
下面的代碼是返回100.78.162.xxx
IP,我想知道我們如何可以確定該IP的位置國家在PHP或Android它自己。任何幫助?如何檢查我的移動IP地址
public static String getIPAddress(boolean useIPv4) {
try {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface intf : interfaces) {
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
for (InetAddress addr : addrs) {
if (!addr.isLoopbackAddress()) {
String sAddr = addr.getHostAddress().toUpperCase();
boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
if (useIPv4) {
if (isIPv4)
return sAddr;
} else {
if (!isIPv4) {
int delim = sAddr.indexOf('%'); // drop ip6 port suffix
return delim<0 ? sAddr : sAddr.substring(0, delim);
}
}
}
}
}
} catch (Exception ex) { } // for now eat exceptions
return "";
}
String ip = Utils.getIPAddress(true);
您需要一個將IP映射到國家/地區的數據庫。這裏的關鍵字是「GeoIP」。只是谷歌它... – bidifx
請看看下面類似的問題: [http://stackoverflow.com/questions/7766978/geo-location-based-on-ip-address-php][1] [1]:http://stackoverflow.com/questions/7766978/geo-location-based-on-ip-address-php – Tikky
這可能是有用的:http://stackoverflow.com/questions/6437172/how-知道地理位置的IP地址 – Badrul