CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 8 FirstFirst 12345 ... LastLast
Results 16 to 30 of 111
  1. #16
    Join Date
    Aug 1999
    Location
    Wisconsin
    Posts
    507
    Originally posted by Mick_2002
    There is a ton of code out there that uses ping to test connectivity before connection, it's even more useful with COM...Older OS/2 ip stacks were fairly unstable so ping was the option of choice before the socket connection.
    This is a bit beyond what Jennings wanted, but what about
    cases where one is not using TCP/IP? Also, some firewalls
    may block ping. It would be nice if there was a function
    that did not need ping.

  2. #17
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by kochhar
    This is a bit beyond what Jennings wanted, but what about
    cases where one is not using TCP/IP? Also, some firewalls
    may block ping. It would be nice if there was a function
    that did not need ping.
    Yes there is that chance that they are filter. But in this case, he has stated, I have a program that downloads updates and I'm guessing from his site. So he has control over what he allows in.

    RawSock and SNMP are beyond the scope of this I'll probably reply further later....

  3. #18
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Guys,

    I've finally gotten around to testing out the ping code.

    A few more questions if I may ...

    My work blocks incoming traffic that doesn't come through via the proxy server. Therefore, all pings external to our network will fail.

    However, gethostbyname("slideshowdesktop.com") does return the resolved ip address for my website.

    My thinking is that if i can resolve an internet hostname, then there must be an internet connection right ?
    If the ping then times out, i can assume the presence of a firewall?

    I'm wondering if simply using gethostbyname() on it's own is all i need to detect the presence of an internet connection ?

    Thanks

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  4. #19
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by jase jennings
    Guys,

    I've finally gotten around to testing out the ping code.

    A few more questions if I may ...

    My work blocks incoming traffic that doesn't come through via the proxy server. Therefore, all pings external to our network will fail.

    However, gethostbyname("slideshowdesktop.com") does return the resolved ip address for my website.

    My thinking is that if i can resolve an internet hostname, then there must be an internet connection right ?
    If the ping then times out, i can assume the presence of a firewall?

    I'm wondering if simply using gethostbyname() on it's own is all i need to detect the presence of an internet connection ?

    Thanks
    DNS does not resolve connectivity (other than to the DNS server), just resolves the IP address listed in the DNS's db.
    They don't have to have a DNS server, they can use a local host file, which is the same issue as above, but your not connecting to a DNS server, therefore your still clueless on whether you have connnectivity.

    BTW: I can ping/tracert slideshowdesktop.com/www.slideshowdesktop.com so is the statement your making correct?

  5. #20
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Thanks for the reply Mick

    1. If i ping slideshowdesktop.com from cmd prompt, it comes back with "Pinging slideshowdesktop.com [216.167.114.177] ..."

    The requests then either time out, or it returns "Reply from [proxy server adddress] : ndestination host unreachable.

    Same happens if i try it with microsoft.com

    So, I'm assuming the recvfrom timesout due to the firewall / proxy

    However, and this is the important part to me, the very fact that slideshowdesktop.com resolves back to an ip address must surely indicate that there is a connection to an external network (i.e. the internet)? To resolve the ip address, it must have communicated with one of the 13 major route DN servers ?I doubt very much if anybody will put slideshowdesktop.com in their hosts file

    Any thoughts?

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  6. #21
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by jase jennings
    Thanks for the reply Mick

    1. If i ping slideshowdesktop.com from cmd prompt, it comes back with "Pinging slideshowdesktop.com [216.167.114.177] ..."

    The requests then either time out, or it returns "Reply from [proxy server adddress] : ndestination host unreachable.

    Same happens if i try it with microsoft.com

    So, I'm assuming the recvfrom timesout due to the firewall / proxy

    However, and this is the important part to me, the very fact that slideshowdesktop.com resolves back to an ip address must surely indicate that there is a connection to an external network (i.e. the internet)? To resolve the ip address, it must have communicated with one of the 13 major route DN servers ?I doubt very much if anybody will put slideshowdesktop.com in their hosts file

    Any thoughts?
    Well, it does not mean _it_ communciated with one of the Major DNS servers, it means also it could communicate with it's own nameserver (it depends on the configuration), which is set to point to another name server in the hierarchy and replicate databases.

    Just because you can resolve an address, does not mean the address is up, and as you can fail to resolve an address, does not mean that address is down. It's just a name to public block IP address lookup, it's not a connectivity check.

    Suppose you failed to resolve the address. Again this doesn't mean your site is down, it means that you for whatever reason didn't get an authoriative answer from your DNS server for your address. And as long as router configuration and tables are up to par, I can still use your IP addr to connect.

    You could probably go with the ping request timeout since you can tweak the timer on waiting for a reply in the call.

    Either way, you should have a waitcursor/message saying your checking for updates....or do it in the background and if you find updates, then either update your code on the next run, or prompt the user if they want to update with the new code. Or check when your program exits. Lots of ways not to interfere with the user.

  7. #22
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Originally posted by Mick_2002
    Well, it does not mean _it_ communciated with one of the Major DNS servers, it means also it could communicate with it's own nameserver (it depends on the configuration), which is set to point to another name server in the hierarchy and replicate databases.
    Why would my company list slideshowdesktop.com in their nameserver ? I can't figure out how gethostbyname() can return an ip address to my website without communicating with a server outside of my companies internal network ...

    Just because you can resolve an address, does not mean the address is up, and as you can fail to resolve an address, does not mean that address is down. It's just a name to public block IP address lookup, it's not a connectivity check.
    Agreed. However, I'm not interested whether the address is up. I just want to know if a computer external to my network can be reached, thus indicating the internet.

    Suppose you failed to resolve the address. Again this doesn't mean your site is down, it means that you for whatever reason didn't get an authoriative answer from your DNS server for your address. And as long as router configuration and tables are up to par, I can still use your IP addr to connect.
    If I cannot resolve the address, then my using InternetOpenURL() on slideshowdesktop.com is going to fail. So not being able to resolve an address is as good as "site down" according to my updater. I do not wish to code in a static ip address for my update server, in case the provider changes it (or even i change provider) - if the ip changed in the future, this would 'break' my updater for older versions of the software.

    You could probably go with the ping request timeout since you can tweak the timer on waiting for a reply in the call.
    The problem is, my company does not allow icmp echo requests inbound, so the ping packets are never received. However, I am connected to the Internet ! Ping fails, but gethostbyname() succeeds.

    Either way, you should have a waitcursor/message saying your checking for updates....or do it in the background and if you find updates, then either update your code on the next run, or prompt the user if they want to update with the new code. Or check when your program exits. Lots of ways not to interfere with the user.
    I've had an Instant Updater in my software for 18 months now, but it doesn't work on a LAN with a firewall, and incorrectly determines the availability of the Internet when using a cable modem/router - it works perfect with dialup connections (even DSL) and across ICS. I'm now looking to address the issues

    My updater is highly configurable.

    1. will run silently in the background (when the internet is available), and popup a tray balloon (2k/xp), or a dialog (9x/me/nt4).
    2. can be configured to run every x days, every time the app is run, or never
    3. automatically runs every time when the software trial period has expired.
    4. you can specify how you connect to the Internet, to give me a little help in determining the connection.
    5. my updater will handle (and accelerate) the download from my website, then install itself (at users request)

    Actually I've put a lot of design and coding effort into the updater, but I'm still plagued by some configurations saying "connected - look for an update", when the Internet is not available. It doesn't work across proxies either, which is my next big job

    None of the above answers are meant as argumentative or are in disagreement - i'm merely trying to debate the issues with somebody who clearly knows what they're talking about (i.e. you

    Thanks

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  8. #23
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Ahh well that clears it up, I think there was a bit of confusion, as I thought we were talking, how can I reduce the 5 second timeout from a Connect(), which started like in the first or second response here.

    What I want to explain in a round about way, is if your company has a NameServer. Your website name/Ip would most likely be cached, since it would be the authorative server for your domain, so there would be no need to fetch it from another domain name server, but that would be internal to your network and isn't worth discussing futher. But having said that, let us say you do have a nameserver at your site (or you can use this same scenario for a nameserver that your ISP provides within their domain namespace), your name server would then also know how to contact the authorative nameserver for a domain, say like www.microsoft.com. When you fetch that address it would ask the server that manages that domain. So yes you can determine that you are connected to the internet (or have been at some point and the NS db tables haven't kicked off a failed interval db update due to internet downage, I think I use to set my nameservers to 8 hours or 24 hours), provided it's not cached and the endpoint router to the provider isn't down (being picky) At least that's the way I remember it working, but I haven't played with DNS configuration/setup since working for a very small company many a year ago

  9. #24
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Thanks for the info.

    I'll let this info churn around inside my tiny brain for a bit, and if it fails to compute, I may get back to you

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  10. #25
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by jase jennings
    Thanks for the info.

    I'll let this info churn around inside my tiny brain for a bit, and if it fails to compute, I may get back to you
    Just remember whenever I say your network/your name server, I mean in the sense of your being the customer trying to connect to www.slideshowdesktop.com of course

  11. #26
    Join Date
    Apr 2003
    Posts
    52
    You can use HTTP to retrieve your update file or simply use CONNECT to solve proxy issue. I am not sure why you want to check internet connection, why not just send a request to your update server to check if update process works or not.
    So far so good

  12. #27
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    > I am not sure why you want to check internet connection, why > not just send a request to your update server to check if
    > update process works or not.

    Two reasons.

    If i check using wininet functions, and the user is not connected, its launches a dialup. If i want to check in the background, i need first know if the user is connected.

    If i call code which needs to timeout, the application causes slow down on the users pc - it won't hang my app because i do it in a non-ui thread. All the same, it will cause slow down.

    How would you do it?

    I want to check my update server and download a file using http. I need to do it invisibly. If the user is not connected, and they ahve asked to be prompted, then my updater will ask them to connect.

    What's your solution?

    Thanks for you help

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  13. #28
    Join Date
    Oct 1999
    Location
    Missouri, USA
    Posts
    453
    jase jennings,
    I've attached a zip file containing an small application that
    detects a internet connection by looking for the default gateway.
    It has worked for me. If it works in the way that you need,
    I'll post the source code.
    The attached file name is "ReadMib.exe".

    -RCFox
    Attached Files Attached Files
    If you need an answer, don't forget to try this link:
    http://www.codeguru.com/forum/search.php?
    __________________

  14. #29
    Join Date
    Oct 1999
    Location
    Missouri, USA
    Posts
    453
    I've tried using the non-blocking WSAAsyncGetHostByName()
    I guess if you don't have the hostname/IP stored in the
    HOST file, it should work to determine a internet connection
    It worked for me on Win98 -
    I don't have a LAN, routers, electric gas music from Jupiter, etc.
    to try it on.
    I'm curious if it works for others.

    At top of your header file:
    Code:
    #define WM_HOST_RESOLVED (WM_APP + 1)
    Within your class in your header:
    Code:
    HANDLE m_hAsyncRequest;      //class scope handle
    char   m_EntryBuffer[MAXGETHOSTSTRUCT]
    DWORD  m_dwDial;
    
    void   ConnectHost(LPCSTR host);
    void   CancelAsync ();  
    BOOL   SetAutodial();
    BOOL   ResetAutodial();
    just above DECLARE_MESSAGE_ MAP() in your header:
    Code:
    	afx_msg LRESULT OnHostResolved(WPARAM wParam, LPARAM lParam);
    	DECLARE_MESSAGE_MAP() //
    Near the top of your cpp :
    Code:
    #include<winsock2.h>
    In your dialog cpp just above END_MESSAGE_MAP:
    Code:
      ON_MESSAGE(WM_HOST_RESOLVED, OnHostResolved)
    END_MESSAGE_MAP()
    Add to your dialog cpp's OnInitDialog :
    Code:
    //disable AutoDial
    SetAutodial(); 
    //set async task handle to null
    m_hAsyncRequest = NULL;
    and in your dialog cpp, for example, these fellas :
    Code:
    //add OnClose message handler
    void CYourDlg::OnClose() 
    {
      //set EnableAutodial to original setting
      ResetAutodial();
    
      CDialog::OnClose();
    }
    
    
    void CYourDlg::OnButton1() 
    {
       //don't call unless previous attempt is completed
       if (!m_hAsyncRequest)
       {
    
         ConnectHost("google.com");
    
       }
    }
       
    void CYourDlg::ConnectHost (LPCSTR host)
    {
      
       WSADATA WSAData;
       WSAStartup (MAKEWORD( 2, 2 ), &WSAData);
      
       memset((char *)m_EntryBuffer, 0x0, sizeof(MAXGETHOSTSTRUCT) );
    
       m_hAsyncRequest= WSAAsyncGetHostByName(m_hWnd,
                                         WM_HOST_RESOLVED, 
                                          (LPCSTR) host,
    	                            (char *)m_EntryBuffer,	
    	    	                    MAXGETHOSTSTRUCT);
    }
    
    void CYourDlg::CancelAsync()
    {
    	if(m_hAsyncRequest)
    	  WSACancelAsyncRequest(m_hAsyncRequest); 
    	else
    	  return;
    
    	m_hAsyncRequest = NULL; 
    	return;
    }
    				   
    
    LRESULT CYourDlg::OnHostResolved(WPARAM wParam, LPARAM lParam)
    {  
       	if(!WSAGETASYNCERROR(lParam) )
    	{
    	 //do something here...
                //m_edit1 = "Connected";
    	}
    	else
    	{
    	 //do something here...
                // m_edit1 = "Not Connected";
    	}
    
    	UpdateData(FALSE);
    	
    	CancelAsync();
    
            WSACleanup ();
        
    	return TRUE;
    }
    
    
    BOOL CYourDlg::SetAutodial()
    {
      BOOL  bResult = FALSE;
      DWORD dwDialType = REG_DWORD;
      DWORD dwDialSize = 4;
      DWORD dwNew = 0;
      HKEY hKeyAutoDial;
    
      if (RegOpenKeyEx(HKEY_CURRENT_USER,
    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_QUERY_VALUE | KEY_SET_VALUE,&hKeyAutoDial) == ERROR_SUCCESS)
     {
       if (RegQueryValueEx(hKeyAutoDial,
                         "EnableAutodial",
    	               NULL,	
                          &dwDialType,
                          (BYTE *)&m_dwDial,
                          &dwDialSize) == ERROR_SUCCESS)
       {
         if (RegSetValueEx(hKeyAutoDial,
    	                    "EnableAutodial",
     		            NULL,
                                dwDialType,
                                (BYTE *)&dwNew,
    	                    dwDialSize) != ERROR_SUCCESS)
          bResult = TRUE;
        
      }
      
      RegCloseKey(hKeyAutoDial);
     } 
      return bResult;
    }
    
    BOOL CYourDlg::ResetAutodial()
    {
      BOOL bResult = FALSE;
      DWORD dwDialType = REG_DWORD;
      DWORD dwDialSize = 4;
      
      HKEY hKeyAutoDial;
    
      if ( m_dwDial )
      {
       if(RegOpenKeyEx(HKEY_CURRENT_USER,
     "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0,KEY_SET_VALUE,&hKeyAutoDial) == ERROR_SUCCESS)
       {
         if(RegSetValueEx(hKeyAutoDial,
                             "EnableAutodial",
                              NULL,
                              dwDialType,
                              (BYTE *)&m_dwDial,
    	                   dwDialSize) == ERROR_SUCCESS)
          bResult = TRUE;
    
       } 
       RegCloseKey(hKeyAutoDial);
      }
      return bResult;
    }
    ** Note: There should be no space between the quotation mark
    and Software\\Micro... that is, it should be "Software\\Micro.."
    If you need an answer, don't forget to try this link:
    http://www.codeguru.com/forum/search.php?
    __________________

  15. #30
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Hi

    Thanks for posting the code. However, it's not really a suitable approach.

    1. "Not Connected" takes too long to time out
    2. An asynchronous check is unsuitable, because the program needs to wait while it looks for a conection (it will still pump messages , but that's all)
    3. If i run the test dlg while connected and then click the button, it will say connected. If i now close the inet connection and press the button again, it will still say i am connected. In fact, it willl continue always to say i am connected until i close the test dlg and run it again. Only then will it tell me "not conected", and it can take 20 seconds to respond.

    I need a solution which works in a few seconds max, and will report correctly connected/not connected, even when the state of the connection changes during the lifetime of the running app.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

Page 2 of 8 FirstFirst 12345 ... LastLast

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

Featured