<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Could someone write me this easy, short java program? 10 points!?</title>
	<atom:link href="http://dwarfprinting.com/381/could-someone-write-me-this-easy-short-java-program-10-points/feed/" rel="self" type="application/rss+xml" />
	<link>http://dwarfprinting.com/381/could-someone-write-me-this-easy-short-java-program-10-points/</link>
	<description>Big Printing For Little Companies</description>
	<pubDate>Sat, 19 May 2012 04:20:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: tgtips</title>
		<link>http://dwarfprinting.com/381/could-someone-write-me-this-easy-short-java-program-10-points/comment-page-1/#comment-1321</link>
		<dc:creator>tgtips</dc:creator>
		<pubDate>Wed, 12 May 2010 14:27:11 +0000</pubDate>
		<guid isPermaLink="false">http://dwarfprinting.com/381/could-someone-write-me-this-easy-short-java-program-10-points/#comment-1321</guid>
		<description>Hi,

There are several means to achieve your goal, but only since Java 1.5 onwards when they began supporting low level port controls.

Having said, several ways, I cannot think of a short way, however, here is some code that would allow the user to enter a web address and get the IP, or to enter an IP and get the web address.

If you do not want both, just delete the one you'd rather not use, or comment it out using either // or /* */

Here goes:

import java.net.*;
import java.io.*;

public class nslookup {

public static void main (String args[]) {

BufferedReader myInputStream =
new BufferedReader(new InputStreamReader(System.in));

System.out.println(&#34;Name Service lookup utility\r\n&#34;+
&#34;Enter names or IP addresses. Enter \&#34;exit\&#34; to quit.&#34;);
while (true) {
String inputString;
try {
System.out.print(&#34;&#62; &#34;);
inputString = myInputStream.readLine();
}
catch (IOException e) {
break;
}
if (inputString.equals(&#34;exit&#34;)) break;
lookup(inputString);
}
} /* end main */
private static void lookup(String s) {
InetAddress address;
// get the bytes of the IP address
try {
address = InetAddress.getByName(s);
}
catch (UnknownHostException ue) {
System.out.println(&#34;** Can't find host &#34; + s);
return;
}
if (isHostname(s)) {
System.out.println(&#34; Address: &#34;+address.getHostAddress());
}
else { // this is an IP address
System.out.println(&#34; Name: &#34;+address.getHostName());
}
} // end lookup
private static boolean isHostname(String s) {
char[] ca = s.toCharArray();
// if we see a character that is neither a digit nor a period
// then s is probably a hostname
for (int i = 0; i &#60; ca.length; i++) {
if (!Character.isDigit(ca[i]) &#38;&#38;
ca[i] != '.') return true;
}
// Everything was either a digit or a period
// so s looks like an IP address in dotted quad format
return false;
} // end isHostName
} // end nslookup

Regards,

TgTips

PS:  I saw you original post also, but it was not one of those 2 min answers, so after writing some code, I noticed you reposted and figured I better reply to this one.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>There are several means to achieve your goal, but only since Java 1.5 onwards when they began supporting low level port controls.</p>
<p>Having said, several ways, I cannot think of a short way, however, here is some code that would allow the user to enter a web address and get the IP, or to enter an IP and get the web address.</p>
<p>If you do not want both, just delete the one you&#8217;d rather not use, or comment it out using either // or /* */</p>
<p>Here goes:</p>
<p>import java.net.*;<br />
import java.io.*;</p>
<p>public class nslookup {</p>
<p>public static void main (String args[]) {</p>
<p>BufferedReader myInputStream =<br />
new BufferedReader(new InputStreamReader(System.in));</p>
<p>System.out.println(&quot;Name Service lookup utility\r\n&quot;+<br />
&quot;Enter names or IP addresses. Enter \&quot;exit\&quot; to quit.&quot;);<br />
while (true) {<br />
String inputString;<br />
try {<br />
System.out.print(&quot;&gt; &quot;);<br />
inputString = myInputStream.readLine();<br />
}<br />
catch (IOException e) {<br />
break;<br />
}<br />
if (inputString.equals(&quot;exit&quot;)) break;<br />
lookup(inputString);<br />
}<br />
} /* end main */<br />
private static void lookup(String s) {<br />
InetAddress address;<br />
// get the bytes of the IP address<br />
try {<br />
address = InetAddress.getByName(s);<br />
}<br />
catch (UnknownHostException ue) {<br />
System.out.println(&quot;** Can&#8217;t find host &quot; + s);<br />
return;<br />
}<br />
if (isHostname(s)) {<br />
System.out.println(&quot; Address: &quot;+address.getHostAddress());<br />
}<br />
else { // this is an IP address<br />
System.out.println(&quot; Name: &quot;+address.getHostName());<br />
}<br />
} // end lookup<br />
private static boolean isHostname(String s) {<br />
char[] ca = s.toCharArray();<br />
// if we see a character that is neither a digit nor a period<br />
// then s is probably a hostname<br />
for (int i = 0; i &lt; ca.length; i++) {<br />
if (!Character.isDigit(ca[i]) &amp;&amp;<br />
ca[i] != &#8216;.&#8217;) return true;<br />
}<br />
// Everything was either a digit or a period<br />
// so s looks like an IP address in dotted quad format<br />
return false;<br />
} // end isHostName<br />
} // end nslookup</p>
<p>Regards,</p>
<p>TgTips</p>
<p>PS:  I saw you original post also, but it was not one of those 2 min answers, so after writing some code, I noticed you reposted and figured I better reply to this one.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

