Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- // Single port scanner
- public class Probe implements Runnable {
- private Socket socket;
- private int port;
- private int timeout; // timeout in milliseconds for the socket
- private InetAddress host_address;
- // Constructor
- public Probe (InetAddress host_address, int port, int timeout) throws PortException {
- if(port <=0 || port > 65535)
- throw new PortException("Invalid port number");
- if(timeout < 0)
- throw new PortException("Invalid timeout");
- // setting properties
- this.setPort(port);
- this.setAddress(host_address);
- this.setTimeout(timeout);
- }
- // Getters and setters
- public int getPort() { return port; }
- public int getTimeout() { return timeout; }
- public InetAddress getAddress() { return host_address; }
- public void setPort(int v) { port = v; }
- public void setTimeout(int v) { timeout = v; }
- public void setAddress(InetAddress v) { host_address = v; }
- // Run method
- @Override
- public void run () {
- try {
- socket = new Socket();
- socket.connect(new InetSocketAddress(this.getAddress(), this.getPort()), this.getTimeout());
- System.out.println("Port [" + this.getPort() + "] \t\t OPEN");
- } catch (Exception e){
- // do nothing: the port is closed or some error happened
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement