Results 1 to 11 of 11

Thread: Check if website exists

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Resolved Check if website exists

    Hi,
    I want to create a form, that run throught all url's in my "members" table, and check if the website actually exists.
    Reason is that the data capturer's here did not check this when they captured.
    My capturing application check if it's a valid url (regex) but that's about it.

    I remember when i was working at microsoft (tester) we had this component used to open a url in a browser, and read elements, but forgot what was that.

    Anyone know how to check this from a c# desktop app?
    Last edited by StrangerInBeijing; Apr 4th, 2007 at 09:59 PM. Reason: Resolved
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  2. #2
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Check if website exists

    You could write a class to ping the website. Just you do in the windows command prompt.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  3. #3

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Check if website exists

    Just got this and tested it, and works fine it's seems:
    Code:
    public static bool UrlIsValid(string smtpHost)
    {
    	bool br = false;
    	try 
    	{
    		System.Net.IPHostEntry ipHost = System.Net.Dns.Resolve(smtpHost);
    		br = true;
    	}
    	catch 
    	{
    		br = false;
    	}
    	return br;
    }
    Pinging would not been a good idea. It's possible for a host to disable that (not sure what it's called), but experienced that before.

    Thanks anyhow for bothering to reply
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Check if website exists

    Hey, I used your code, it worked fine for yahoo.com but not working for any other site, microsoft.com, vbforums.com, msn.com, none for!!

    Is it working for you for all websites??
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Check if website exists

    Strange, because it's working fine for all the sites you mentioned. I tested it also with sites I know does not exists, like www.dasfljdaskfsadfjsad.com, and then it return false.

    Noticed that if you add the "http://" then it always return false, but with or without www it's fine.

    Not so sure about this....the reason why I hate having so little time, and end up just re-using code, instead of learning how it works. Gawd, I need a new job!
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Check if website exists

    Quote Originally Posted by StrangerInBeijing
    Noticed that if you add the "http://" then it always return false, but with or without www it's fine.
    I'm pretty sure that's because the protocol has nothing to do with Resolving DNS records.

    For example:
    http://www.example.com/
    ftp://www.example.com/

    Are the same server (www.example.com).



    If you're taking user data, it might be an idea to strip any protocols off the front, and even / at end, possibly even index.php (for example), you know never to trust users with what they enter.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if website exists

    Rudi is correct. The protocol is not part of the DNS record. Neither is the trailing slash, although that doesn't matter so much.

    Note that www.example.com and example.com are separate records.

  8. #8
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Check if website exists

    Ok, today it's quite working.

    Rudi and Penagate stated correctly, http:// has nothing to do with DNS. In fact, if I add http:// to my example, it would return exception "No such host is known".

    But adding/subtracting www doesn't make any difference.

    This is a simple thing I tried:
    Code:
    try
            {
                System.Net.IPHostEntry host;
    
                host = System.Net.Dns.GetHostEntry("del.icio.us");
    
                if (host != null)
                    Console.WriteLine("It exists");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
    Quote Originally Posted by penagate
    Note that www.example.com and example.com are separate records.
    Could you elaborate this please??

    Thank you
    Show Appreciation. Rate Posts.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if website exists

    They're not the same domain. Although most people use both to point to the same site, it's quite possible to point them in different directions (often with quite confusing results).

  10. #10
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Check if website exists

    Yeah, for example, instead of www. and *nothing*.

    Think of:
    server1.example.com
    server2.example.com

    They would point to different servers, same with www. and *nothing*.

    Another way to possibly clarify it is if example.com wasn't meant to be on the web, just registered, or something, perhaps an intranet domain, you don't want www. infront of it, as it's not on the world wide web (www).

    Probably confused things more, but, whatever, hopefully you'll understand.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if website exists

    Personally, I don't see the point of www; I hard redirect the www address of all sites I manage to the non-www form. It looks cleaner that way and you don't have people getting confused with different cookies and so on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width