Created
December 27, 2013 10:05
-
-
Save NusZzz/8144879 to your computer and use it in GitHub Desktop.
midterm network programming.
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.net.*; | |
import java.io.*; | |
public class midterm{ | |
public static void main(String[] args) throws IOException{ | |
try{ | |
InetAddress address = InetAddress.getByName("www.mfu.ac.th"); | |
String nameAddress = ""+address; | |
InetAddress secret_address = InetAddress.getByName("202.28.46.8"); | |
String secret_address1 = ""+secret_address; | |
int slashPosition = nameAddress.indexOf('/'); | |
String onlyName = nameAddress.substring(0, slashPosition); | |
String onlyIP = nameAddress.substring(slashPosition+1, nameAddress.length()); | |
System.out.println("Name is " + onlyName); | |
System.out.println("IP is " + onlyIP); | |
if(secret_address1.equals("/"+onlyIP)){ | |
System.out.println("It's the same address"); | |
}else{ | |
System.out.println("It's not the same address"); | |
} | |
}catch(Exception ex){ | |
System.out.print("No address found!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment