首页 > 代码库 > Java 查询URL对应IP地址
Java 查询URL对应IP地址
/** * @ClassName TestSocket1 * @Version 1.0 * @Date 2014-9-26 上午10:19:36 */public class TestSocket1 { public static void main(String[] args) throws UnknownHostException { String str = ""; Scanner scanner = new Scanner(System.in); while (true) { System.out.println("请输入需要查询的URL:"); str = scanner.nextLine().trim(); if (str.equalsIgnoreCase("exit")) { System.out.println("程序退出"); break; } else if (str.length() == 0) { System.out.println("本机IP " + getLocalHost(str)); } else { System.out.println(Arrays.toString(getWebHost(str).toArray())); } } } private static String getLocalHost(String url) throws UnknownHostException { return InetAddress.getLocalHost().toString(); } private static List<String> getWebHost(String url) throws UnknownHostException { List<String> res = new LinkedList<String>(); InetAddress[] address = InetAddress.getAllByName(url); for (InetAddress inetaddress : address) { res.add(inetaddress.getHostAddress()); } return res; }}
Java 查询URL对应IP地址
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。