2

i'm tring to run argument from ubuntu console.

./myTool -h

and all i get is only the print of "1".

someone can help please ?

thanks !

public static void main(String[] argv) throws Exception
{

    System.out.println("1");
    for(int i=0;i<argv.length;i++)
    {
        if (argv.equals("-h"))
        {
            System.out.println("-ip   target ip address\n");
            System.out.println("-t    time interval between each scan in milliseconds\n");
            System.out.println("-p    protocol type [UDP/TCP/ICMP]\n");
            System.out.println("-type scan type [full,stealth,fin,ack]\n");
            System.out.println("-b    bannerGrabber status\n");

        }

}

OrMoush
  • 195
  • 1
  • 7

4 Answers4

2

argv is an entire array. What you are trying to match, is the entire content of the array with the string -h. Try doing this:

public static void main(String[] argv) throws Exception
{

    System.out.println("1");
    for(int i=0;i<argv.length;i++)
    {
        if (argv[i].equals("-h"))
        {
            System.out.println("-ip   target ip address\n");
            System.out.println("-t    time interval between each scan in milliseconds\n");
            System.out.println("-p    protocol type [UDP/TCP/ICMP]\n");
            System.out.println("-type scan type [full,stealth,fin,ack]\n");
            System.out.println("-b    bannerGrabber status\n");

        }
     }
}

Side Note: This previous SO post might also be worth going through.

Community
  • 1
  • 1
npinti
  • 51,070
  • 5
  • 71
  • 94
2

You miss the array index in the if condition:

argv[i].equals("-h")
Drogba
  • 3,986
  • 4
  • 20
  • 29
0

You are comparing an array with a string. Change it to:

   if (argv[i].equals("-h"))
Klas Lindbäck
  • 32,669
  • 4
  • 56
  • 80
0

You try to compare String[] with String.

Try instead:

    if (argv[i].equals("-h"))
BobTheBuilder
  • 18,283
  • 5
  • 37
  • 60