java program
import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import java.net.SocketException; import java.net.UnknownHostException; public class Main { public static void main(String[] args) { try { InetAddress addr = InetAddress.getByName("74.125.67.100"); Socket theSocket = new Socket(addr, 80); System.out.println("Connected to " + theSocket.getInetAddress() + " on port " + theSocket.getPort() + " from port " + theSocket.getLocalPort() + " of " + theSocket.getLocalAddress()); } catch (UnknownHostException e) { System.err.println("I can't find " + e ); } catch (SocketException e) { System.err.println("Could not connect to " +e ); } catch (IOException e) { System.err.println(e); } } }
Output
Connected to /74.125.67.100 on port 80 from port
2857 of /192.168.1.4
- Implementation of MD5 Algorithm in Java
- Implementation of RSA Algorithm(Encryption and Decryption) in Java
- java program to get the date of URL connection
- java program to read and download a webpage
- java program to find hostname from IP Address
- java program to determine IP Address & hostname of Local Computer?
- java program to check whether a port is being used or not
- java program to find proxy settings of a System
- java program to create a socket at a specific port
- java program to get the parts of an URL