2

trying to ping a domain and see if i get a response code to get a indication if its registered. getting constant positive results from the following code - any ideas?

public static string Check(string keyword)
    {
        Ping pingSender = new Ping();
        PingOptions options = new PingOptions();

        // Use the default Ttl value which is 128,
        // but change the fragmentation behavior.
        options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes(data);
        int timeout = 120;
        PingReply reply = pingSender.Send(keyword, timeout, buffer, options);
        if (reply.Status == IPStatus.Success)
        {

            return "found";
        }
        else
        {
            return "not found";
        }
    }


    private void hunt_Click(object sender, EventArgs e)
    {
        string keyword = txtKeyword.Text;
        txtOutput.Text = Check(keyword);
    }

any help is appreciated :-)

loveforfire33
  • 1,090
  • 3
  • 25
  • 46
  • Can you write for which keywords you tried to execute it? – Aleksandar Vucetic Jan 15 '12 at 23:02
  • possible duplicate of [Header Check C# is always 403?](http://stackoverflow.com/questions/8874839/header-check-c-sharp-is-always-403) – Jason Jan 16 '12 at 13:13
  • I've tried running the code above with the domain "www.goosdfdsgle.com" and get a socket exception thrown "This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server". Seems like the correct behaviour. – Slugart Jan 16 '12 at 19:26

1 Answers1

0

hey i ran this code and it works, (exception is thrown when worng IP or DNS is entered) why not use this overload?

       public static string Check(string keyword)
         {
        Ping pingSender = new Ping();
        //PingOptions options = new PingOptions();

        // Use the default Ttl value which is 128, 
        // but change the fragmentation behavior. 
       // options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted. 
        //string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        // byte[] buffer = Encoding.ASCII.GetBytes(data);
        // int timeout = 120;
        try
        {
            PingReply reply = pingSender.Send(keyword);
            return "found";
        }
        catch
        {
            return "not found";
        }


    }
Liran
  • 591
  • 3
  • 13