Skip to content

Commit 11bd10f

Browse files
Initial code uploaded.
1 parent ac28325 commit 11bd10f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

scripts/SocketToPort.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.net.InetAddress;
2+
import java.net.Socket;
3+
import java.net.SocketException;
4+
import java.net.UnknownHostException;
5+
import java.io.IOException;
6+
7+
public class SocketToPort {
8+
public static void main(String[] args) {
9+
try {
10+
InetAddress address = InetAddress.getByName("179.105.231.48");
11+
Socket socket = new Socket(address, 80);
12+
System.out.println("Established connection to "
13+
+ socket.getInetAddress()
14+
+ " on port #" + socket.getPort() + " from port #"
15+
+ socket.getLocalPort() + " of device IP "
16+
+ socket.getLocalAddress());
17+
} catch (UnknownHostException e) {
18+
System.err.println("Cannot find host: " + e );
19+
} catch (SocketException e) {
20+
System.err.println("Cannot establish connection: " +e );
21+
} catch (IOException e) {
22+
System.err.println(e);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)