原文:java脚本开发根据客户IP获取IP的具体地理位置信息
源代码下载地址:http://www.zuidaima.com/share/1550463468522496.htm
根据客户IP获取IP的具体地址
运行结果:
package com.zuidaima.founder.util.ip;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* 功能描述:测试
*@author www.zuidaima.com
*/
public class IPtest{
public static void main(String[] args) {
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
String ipStr = addr.getHostAddress().toString();// 获得本机IP
String addressStr = addr.getHostName().toString();// 获得本机名称
System.out.println("本机IP地址: " + ipStr + " 本机名称: " + addressStr);
String ipInfo = "120.197.41.37";
System.out.println("IP地址: " + ipInfo);
// 指定纯真数据库的文件名,所在文件夹
IPSeeker ip = new IPSeeker();
System.out.println("IP所属地:" + ip.getIPLocation(ipInfo).getCountry() + " " + ip.getIPLocation(ipInfo).getArea());
}
}