Program Crashes.

I have been creating this program for a while now.. its a program that scans my works network IP's to see there hostnames.. and remove ip addr that does not have any host names.. but the program keeps crashing... The program crashes when I enter an IP address that does not have a hostname.. Can someone point me on the right direction Also.. Please forgive the way I coded it... I'm still learning.. and I'm still reading tutorials on a daily basis. Anyways.. I added the codes in a pastebin.. also any recommendations on the program would be helpfull.

here is the link to the codes...   http://pastebin.com/823524


P.S: Unless you want me to post it here.. I will.



Answer this question

Program Crashes.

  • netleon

    Hey Mike, nm I got it working.. I guess Im just a little tired here.. now I feel embarest :S, thanx for your help me.


  • Ahoapap

    Hmm... on a quick look the code seems correct. What error are you getting and where


  • Conde_tkd

    But your code already does this. You have the GetHostEntry call in a try block and in the catch you set the checkbox text to the input string.
  • raaj_001

    The program loads fine.. but when I add a few IP Addresses.. for example an Ip that does not have a domain name.. it crashes.. it starts at line 164 in the pastebin link. Can you run the program and see it for your self I build it using my text editor and compiled it with .Net FrameWork.


  • BigWinston

    Ya.. but its not catching it :( its weird.. see.. I even modded abit to see.

    string[] strings = list.ToArray();

    CheckBox[] chk = new CheckBox[strings.Length];

    for( int x = 0; x < strings.Length; x++ )
    {
    if( Regex.IsMatch( strings[x], @"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$" ) == false )
    {
    MessageBox.Show( "There is an error in your Input" );

    }else{

    if( strings[x] != null )
    {
    try {

    this.Cursor = Cursors.WaitCursor;

    IPHostEntry ipHostEntry = Dns.GetHostEntry( strings[x].ToString());

    chk[x] = new CheckBox();
    chk[x].Location = new Point( 10, 30 * x );
    chk[x].Size = new Size( 350, 40 );
    chk[x].Text = ipHostEntry.HostName;

    pnl2.Controls.Add( chk[x] );

    }catch( Exception exc ) {

    MessageBox.Show( exc.Message, "TestDNS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );

    }finally {

    this.Cursor = Cursor;
    }
    }
    }

    I keep getting the same debugging box as before... just with a different message. but shouldnt the try/catch work


  • Joeku

    hhm I see another error.. but its because Im adding an unknown host in the box.. what would be the best way for me to catch this and just pring out the ip


  • Mike Sage

    hm thats weird.. I dont see were I set the chk array to 10... this is what I have..

    string[] strings = list.ToArray();

    for( int x = 0; x < strings.Length; x++ )
    {
    if( strings[x] != "" && strings[x] != null )
    {
    try {

    IPHostEntry ipHostEntry = Dns.GetHostEntry( strings[x].ToString());
    chk[x] = new CheckBox();
    chk[x].Location = new Point( 10, 30 * x );
    chk[x].Size = new Size( 350, 40 );

    foreach(IPAddress ipAddress in ipHostEntry.AddressList)
    {
    chk[x].Text = ipHostEntry.HostName;
    }
    }catch( Exception e ) {

    chk[x].Text = strings[x];
    }

    pnl2.Controls.Add( chk[x] );
    }
    }


    ------- edit --------

    Oh I see.. ok Will try it out.


  • Kev Wu

    RizwanSharp wrote:

    Same here as Mike Said,

    I also ran it and provided some IP Addressses and did not have any crash!!!

    Secondly I wonder you are using a text editor to write the code and C# Compiler to compile and run..... Its really weird for me to wirte some small application in 10x time all with hand. Why dont you download free C# Express Editon it supprts almost everything a hobbiest developer needs!

    Please dont wait to get it from here for free:

    http://msdn.microsoft.com/vstudio/express/visualcsharp/

    Best Regards,

    thanx for the recommendations.. but I like doing things raw this way I can learn and know what is going on, also once I learn I will be doing some big apps.. anyways.. I made a snapshot of the error message... you can view it here.. http://dbmsystempr.com/error.gif


  • Tonnie

    This is probably in line 165, not 164. Your CheckBox array (chk) is only 10 elements in size. If you specify more than 10 addresses as input you get this error. You need to recreate the chk array to have the same size as the strings array:

    1. string[] strings = list.ToArray();
    2. chk = new CheckBox[strings.Length];
    3. for( int x = 0; x < strings.Length; x++ )

  • Ed209

    Does not crash for me. What error message/exception are you seeing At that line is GetHostEntry that can throw various exceptions like "unknown host" or similar.
  • Alvin Kuiper

    Same here as Mike Said,

    I also ran it and provided some IP Addressses and did not have any crash!!!

    Secondly I wonder you are using a text editor to write the code and C# Compiler to compile and run..... Its really weird for me to wirte some small application in 10x time all with hand. Why dont you download free C# Express Editon it supprts almost everything a hobbiest developer needs!

    Please dont wait to get it from here for free:

    http://msdn.microsoft.com/vstudio/express/visualcsharp/

    Best Regards,



  • Program Crashes.