Selasa, 19 April 2011

Mencari IP Address Komputer dengan Menggunakan InetAddress


Contoh pemrograman Java untuk mencari IP Address sebuah komputer jika diketahui nama komputer tersebut dengan menggunakan kelas InetAddress.

Source Code:

import java.net.*;
public class urltest2 {
  public static void main (String args[]) {
    URL webURL, ftpURL;
    String url = "http://myname:mypass@www.example.com:81/a/bc/def/vendor.html?search=a#AKHIR";
    if (args.length == 1) url = args[0];
    try {
      webURL = new URL(url);
      System.out.println("URL = " + webURL);
      String auth, file, host, path, protocol, query, ref, user;
      auth = webURL.getAuthority();
      System.out.println("Authority = "+ auth);
      protocol = webURL.getProtocol();
      System.out.println("Protocol = "+ protocol);
      user = webURL.getUserInfo();
      System.out.println("User Info = "+ user);
      host = webURL.getHost();
      System.out.println("Host = "+ host);
      int port, def_port;
      port = webURL.getPort();
      if (port == -1) port = webURL.getDefaultPort();
      System.out.println("Port = "+ port);
      file = webURL.getFile();
      System.out.println("File = "+ file);
      path = webURL.getPath();
      System.out.println("Path = "+ path);
      query = webURL.getQuery();
      System.out.println("Query = "+ query);
      ref = webURL.getRef();
      System.out.println("Ref = "+ ref);
    }
    catch (MalformedURLException e)  {
      System.err.println("URL Salah");
    }
  }
}
sumber

Related Posts Plugin for WordPress, Blogger...
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Grants For Single Moms