Created
May 11, 2011 15:42
-
-
Save rbochet/966706 to your computer and use it in GitHub Desktop.
This program runs a server that give you the IP address of every client that try to connect. Its quite useful as a whatismyip service on a local network.
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
package fr.stackr.java.gimmeyourip; | |
import java.io.IOException; | |
import java.net.InetAddress; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
/** | |
* This program runs a server that give you the IP address of every client that | |
* try to connect. Its quite useful as a whatismyip service on a local network. | |
* | |
* @author Romain Bochet | |
*/ | |
public class Main { | |
/** | |
* Translation of IP in ascii | |
*/ | |
private final static int PORT_NUMBER = 7380; | |
/** | |
* Endless while waiting for new connections. | |
* | |
* @param args | |
* Not used | |
* @throws IOException | |
* If the socket initialisation fails | |
*/ | |
public static void main(String[] args) throws IOException { | |
System.out.println("GimmeMyIP started (host: " | |
+ InetAddress.getLocalHost() + ") -- listen on port " | |
+ Main.PORT_NUMBER); | |
ServerSocket srv = new ServerSocket(Main.PORT_NUMBER); | |
while (true) { | |
Socket socket = srv.accept(); | |
System.out.println("Client connected: "+socket.getInetAddress()); | |
socket.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment