<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/category/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sat, 23 Nov 2019 13:54:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Java: host2IP &#8211; find the IP address from a host name</title>
		<link>https://blog.andreev.it/2011/12/java-host2ip/</link>
					<comments>https://blog.andreev.it/2011/12/java-host2ip/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Tue, 27 Dec 2011 19:43:53 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=217</guid>

					<description><![CDATA[Recently, I have to find IP addresses for a bunch of hosts from a&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Recently, I have to find IP addresses for a bunch of hosts from a text file. This JAVA program uses Windows nslookup command to find the IP from a host. The input parameter is a text file with the names of the hosts, each host in a separate line.</p>
<p>e.g.<br />
<em>hostname1<br />
hostname2</em></p>
<p>The output is on the screen in the form of:<br />
<em>hostname1<SPACE>IP address1<br />
hostname2<SPACE>IP address2<br />
</em><br />
You can redirect this output to a file “>” and import it in a spreadsheet program.</p>
<pre class="brush: java; title: ; notranslate">
package host2ip;
import java.io.*;
  
public class Main {
  
     public static void main(String&#x5B;] args) {
  
         String strIP = null;
         String strInput = null;
        
         try{
             FileInputStream fstream = new FileInputStream(args&#x5B;0]);
             DataInputStream in = new DataInputStream(fstream);
             BufferedReader br = new BufferedReader(new InputStreamReader(in));
             String strLine;
             while ((strLine = br.readLine()) != null){
                 try {
                     Process p = Runtime.getRuntime().exec(&quot;nslookup &quot; + strLine);
                     BufferedReader stdInput = new BufferedReader(new
                     InputStreamReader(p.getInputStream()));
                     while ((strInput = stdInput.readLine()) != null) {
                         if (strInput.contains(&quot;Address: &quot;)){
                             strIP = strInput.substring(10);
                         }
                     }
                     System.out.println(strLine + &quot; &quot; + strIP);
                 }
                 catch (IOException e) {
                     System.out.println(&quot;Exception: &quot;);
                     e.printStackTrace();
                     System.exit(-1);
                 }
             }
             in.close();
             } catch (Exception e){
                 System.err.println(&quot;Error: &quot; + e.getMessage());
             }
     }
 }
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/java-host2ip/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
