Skip to content

Instantly share code, notes, and snippets.

@NusZzz
Created December 27, 2013 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NusZzz/8144879 to your computer and use it in GitHub Desktop.
Save NusZzz/8144879 to your computer and use it in GitHub Desktop.
midterm network programming.
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