Menu

Extending Port Scanner Application

Help
2017-03-04
2017-03-04
  • Amit Khandelwal

    Amit Khandelwal - 2017-03-04

    Hi,
    I am trying to extend the Simple port Scanner so that it displays the open ports found. For which I made following changes and launched the application. '
    But it turned out that the method "handleIncomingPacket" is never getting executed?
    1. Does that mean the server is not replying? ( I have profiled a server with Echo Server profile)
    2. Or is there a fault in the logic?

    import de.dailab.nessi.core.api.annotations.Description;
    import de.dailab.nessi.core.api.annotations.IntegerField;
    import de.dailab.nessi.core.api.annotations.StringField;
    import de.dailab.nessi.core.api.events.Event;
    import de.dailab.nessi.core.api.events.TickedEvent;
    import de.dailab.nessi.ip.api.address.IPFactory;
    import de.dailab.nessi.ip.api.address.IPv4Address;
    import de.dailab.nessi.ip.api.layer.ILayerHandler;
    import de.dailab.nessi.ip.api.layer.ITransportLayer;
    import de.dailab.nessi.ip.api.protocols.Packet;
    import de.dailab.nessi.ip.api.protocols.ip.IPv4Header;
    import de.dailab.nessi.ip.api.protocols.udp.UDPHeader;
    import de.dailab.nessi.ip.handler.IPApplication;
    import java.util.Random;
    
    public class Port_AK extends IPApplication
    {
    
        public Port_AK()
        {
            startPort = 1;
            endPort = 1024;
            targetIp = "0.0.0.0";
            startTick = 100;
            System.out.print("Inside constructor ");
    
        }
    
        public void handleEvent(Event e)
        {
            System.out.print("Insie handleevent ");
            Random ran = new Random(123L);
            for(int i = startPort; i < endPort; i++)
            {
                System.out.print("Inside for loop ");
                byte payload[] = new byte[28];
                ran.nextBytes(payload);
                getLayerHandler().getTransportLayer().sendUDPPacket(7, i, destinationIP, payload);
            }
            System.out.print("Exiting handle event ");
            //super.handleEvent(e);
        }
    
        public boolean start()
        {
            System.out.print("Inside start ");
            destinationIP = IPFactory.createIPv4Address(targetIp);
            TickedEvent e = new TickedEvent(this, startTick);
            getLayerHandler().addEvent(e);
            System.out.print("Exiing start ");
    
            return super.start();
        }
    
        @Override
        public void handleIncomingPacket(Packet packet) {
            System.out.print("Inside handle incoming packets ");
        IPv4Header ipHeader = packet.findHeader(IPv4Header.class);
        UDPHeader udpHeader = packet.findHeader(UDPHeader.class);
        if (ipHeader == null || udpHeader == null) {
        return;
        }  
        System.out.print("The port replied back is ");
        System.out.println(udpHeader.getSourcePort());
        }
    
        @IntegerField("Start Port")
        @Description("Start Port number")
        private int startPort;
        @IntegerField("End Port")
        @Description("End")
        private int endPort;
        @StringField("IP Address")
        private String targetIp;
        private int startTick;
        private IPv4Address destinationIP;
    }
    
     

    Last edit: Amit Khandelwal 2017-03-04

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.