package getParser.java;
import java.net.*;
class InetAddressTest{
public static void main(String[] args){
InetAddress addr = null;
InetAddress[] addrArr = null;
String name = "www.naver.com";
addr = InetAddress.getByName(name);
System.out.println ("domain name: "+addr.getHostName()));
System.out.println ("IP address: "+addr.getHostAddress()));
System.out.println();
addrArr = InetAddress.getAllByName(name);
for(int i =0; i < addrArr.length;i++){
System.out.println ("IP List["+i+"]): "+addrArr[i]);
}
System.out.println();
addr = InetAddress.getLocalHost();
System.out.println ("Local Host Domain Name:" +addr.getHostName()));
System.out.println ("Local Host IP Address :" +addr.getHostAddress()));
System.out.println();
} } catch(UnknownHostException e){
e.printStackTrace();
}
}
}
The output is showing like this, and there's a question here! Currently, I searched only the address of Naver url and printed out the ip How do I print out hundreds of different url ip addresses at once? It would be better if it's a way to save url in txt and print it outcrying I'm really a beginner at java, so I'd appreciate it if you could attach the source code as well!
java
First of all, you have to have an array of urls.
And repeat the current method by the number of arrays.
String[] names = {"www.naver.com", "www.daum.net"};
//First iteration
for (String url : names) {
addr = InetAddress.getByName(url);
System.out.println ("domain name: " + addr.getHostName()));
System.out.println ("IP address: " + addr.getHostAddress()));
System.out.println();
addrArr = InetAddress.getAllByName(url);
//2nd iteration
for (int i = 0; i < addrArr.length; i++) {
System.out.println ("IP List[" + i + "]): " + addrArr[i]);
}
}
See here for instructions on how to save the file.
© 2024 OneMinuteCode. All rights reserved.