查找用户输入的网站 Ip 的问题

问题描述 投票:0回答:0

我试图找到用户提供的网站的 IP,但出现此错误 我不确定怎么了。我认为代码很好,可以是其他代码吗?

线程“main”中的异常 java.net.UnknownHostException:不知道这样的主机(www.google.gr) 在 java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(本机方法) 在 java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52) 在 java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1059) 在 java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1668) 在 java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1003) 在 java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1658) 在 java.base/java.net.InetAddress.getAllByName(InetAddress.java:1524) 在 java.base/java.net.InetAddress.getByName(InetAddress.java:1413) 在 WebIp.WebsitIp(WebIp.java:11) 在 Main.main(Main.java:47)

这是主要的,除了案例 7


import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        boolean quit = false;
        do {

            System.out.println("Choose:");
            System.out.println("1--Internet Connection");
            System.out.println("2--Operating System");
            System.out.println("3--Local host Ip");
            System.out.println("4--Public Ip");
            System.out.println("5--Network Info");
            System.out.println("6--File System Info");
            System.out.println("7--Website Ip");
            System.out.println("8--EXIT!");
            System.out.println("");
            int option = sc.nextInt();

            switch (option) {
                case 1:

                    IpAndConn.intConn();
                    break;
                case 2:
                    OsSysInfo.OsInf();
                    break;
                case 3:
                    System.out.println("Your LH IP is:");
                    IpAndConn.Ipfind();
                    break;
                case 4:
                    System.out.println("Your Public Ip is: ");
                    ExtIp.PublicIp();
                    break;
                case 5:
                    System.out.println("Your Network Info: ");
                    ListNets.list();
                    break;
                case 6:
                    DriveTypeInfo.fileSysInf();
                    break;
                case 7:
                    WebIp.WebsitIp();

                    break;
                case 8:
                    quit = true;
                    sc.close();

                    break;
                default:
                    System.out.println("Invalid input! Try again");

            }
        } while (!quit);

    }
}

这是我在案例 7 中尝试调用的课程


import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;

public class WebIp extends Main {
    static void WebsitIp() throws UnknownHostException {
        try (Scanner keyb = new Scanner(System.in)) {
            System.out.println("Give a web sites name:");
            String webSite = keyb.nextLine();
            System.out.println(InetAddress.getByName(webSite));
        }

    }
}
java
© www.soinside.com 2019 - 2024. All rights reserved.