Created
November 5, 2014 22:29
-
-
Save javadabadoo/569d6bafb4061f8c0bb7 to your computer and use it in GitHub Desktop.
Port scan
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
import java.rmi.RemoteException; | |
import java.rmi.registry.LocateRegistry; | |
import java.rmi.registry.Registry; | |
public class PortScan { | |
public static void main(String... args) { | |
String host = args[0].equals("-") ? "localhost" : args[0]; | |
int portStarting = Integer.parseInt(args[1]); | |
int portEnding = args.length >= 3 ? Integer.parseInt(args[2]) : portStarting; | |
for (int currentPort = portStarting; currentPort <= portEnding; currentPort++) { | |
Registry registry = null; | |
String[] list = null; | |
try { | |
registry = LocateRegistry.getRegistry(host, currentPort); | |
list = registry.list(); | |
} catch (RemoteException e) { | |
// Si hay bronca es porque no se pudo conectar, no me interesa hacer nada | |
} | |
if (list != null && list.length != 0) { | |
System.out.println("\n" + host + ":" + currentPort); | |
for (String name : list) { | |
System.out.println(" - " + name); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obtener nombre de los puertos del 5 al 10 en localhost
java PortScan - 5 10
Obtener nombre de los puertos del 5 al 10 en el servidor 123.123.123.123
java PortScan 123.123.123.123 5 10
Obtener nombre del puerto 5 en el servidor 123.123.123.123
java PortScan 123.123.123.123 5