Created
May 4, 2017 13:44
-
-
Save fty4/243a3738a262bc20a38955948af3d91b to your computer and use it in GitHub Desktop.
Reads hostnames from file and searches for their IP-addresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.PrintWriter; | |
import java.net.InetAddress; | |
public class getIpFromHostname { | |
public static void main(String[] args) { | |
InetAddress address; | |
try { | |
FileReader fr; | |
FileWriter fw; | |
BufferedReader br; | |
PrintWriter pw; | |
fr = new FileReader("C:\\Marco\\tmp\\hostnames.txt"); | |
br = new BufferedReader(fr); | |
String strText; | |
String iplist = ""; | |
while ((strText = br.readLine()) != null) | |
{ | |
address = InetAddress.getByName(strText); | |
iplist += address.getHostAddress() + "\r\n"; | |
System.out.println(address.getHostAddress()); | |
} | |
br.close(); | |
fr.close(); | |
fw = new FileWriter("C:\\Marco\\tmp\\ips.txt", false); | |
pw = new PrintWriter(fw); | |
pw.write(iplist); | |
pw.close(); | |
fw.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment