Internet
Last Updated: 01/27/2007

Frequently Asked Questions for Internet:

     
  1. About WinInet.DLL and checking for an Internet Connection 
  2. Broadcast over Internet 
  3. Connected to the Internet 
  4. Disconnecting from ISP 
  5. Dynamic IP address 
  6. Getting IE settings 
  7. For an MX-Lookup I need an DNS Server. Where can I find this Server? 
  8. How to get DNS Servers currently used? 

[Back to Main]













  
About WinInet.DLL and checking for an Internet Connection
Angus Robertson angus@magsys.co.uk    
20/01/2002

WinInet.dll is the core DLL that provides most of the winsock functionality for MSIE/WebBrowser, ie http, ftp, cookie management, etc. 

However the InternetGetConnectedState is not magic, and has all the limitations previously discussed.  It is described in Knowledgebase Article #Q242558. An extract is added below:

You cannot rely solely on the fact that InternetGetConnectedState returning TRUE means that you have a valid active Internet connection. It is impossible for InternetGetConnectedState to determine if the entire connection to the Internet is functioning without sending a request to a server. This is why you need to send a request to determine if you are really connected or not. You can be assured however that if InternetGetConnectedState returns TRUE, that attempting your connection will NOT cause you to be prompted to connect to the default Internet Service Provider. Be aware that InternetGetConnectedState only reports the status of the default Internet connectoid on Internet Explorer 4.x. If a nondefault connectoid is connected, InternetGetConnectedState always returns FALSE (unless a LAN connection is used). With Internet Explorer 4.x configured to use a LAN connection, InternetGetConnectedState always returns TRUE. Internet Explorer 5 behaves differently. If you are currently dialed into a different dial-up in Internet Explorer 5, InternetGetConnectedState reports dial-up connection status as long as any connectoid is dialed or an active LAN connection exists.  There are some other ways to try to determine if you currently have a connection to a particular network resource. The IsDestinationReachable() function can be used to find out if there is a current connection to an address. However, he IsDestinationReachable() function is only concerned with whether the IP address is reachable from your computer. It does not work through HTTP proxies or firewalls that restrict ICMP ping packets. It is also possible to use RasEnumConnections to enhance your code so that you can tell if there is an active dialup connection that might have Internet access even though it is not the default Internet dialup connectoid. 


 
[Return to Top]

  
Broadcast over Internet
Francois PIETTE francois.piette@overbyte.be    
26/10/2001

> Why routers are blocking UDP broadcase packets ?

 Broadcasts are blocked by routers because otherwise it would spread all over the internet !

 
[Return to Top]

  
Connected to the Internet
Various    
25/02/2001

> Am I connected to the Internet

There is no perfect solution.  Why?  Because the Internet is just another network.  Your computer does not distinguish between LAN and Internet.  They are both networks.  One of them just happens to be very big.

The Internet is no different to your local network.  It is just a matter of size.

Think about your question.  "Am I connected to the Internet?".  Try rephrasing your question to what you really want to ask.  "Can I connect to a specific remote host?"  With the question worded like this, you can start to tackle the problem.  How do you find out if you can connect to the remote host?  Try to connect.  Simple as that.  If the connection attempt fails, there is no path between you and the remote host or the remote host is refusing connections.

But, I hear you cry, I do not want the auto-dial the pop up.  How do we get around this?  Ask the user how to make a connection.  We see this all the time in other Internet applications.  Outlook Express, WinAmp, etc.  They ask the user what sort of network connection they have.  From this information, the applications can make the best choice about how to connect to a remote host.

There is no proof way. However some things can help:

there is an InternetGetConnectedState function in the WinINet.DLL that returns true if it detects a connection to the internet. However, the only thing you can be sure about when using this funtion is that the computer will not start dialing and not pop up any dialog box when the function returned true and you afterwards try to do anything on the internet. In some cases the function may return false although the computer is connected.

This is another way:

procedure TFrmDiscEditor.TmrInternetConnectionTimer(Sender : TObject);
type
  TGetConnectedState = function(var Flags : Integer; Reserved : Integer) :
Bool;
  StdCall;
var
  WlLib : THandle;
  GetCS : TGetConnectedState;
  State : Integer;
begin
  WlLib := LoadLibrary('wininet.dll');
  if WlLib = 0 then
  begin
    TmrInternetConnection.Enabled := False;
    Exit;
  end;
  GetCS := GetProcAddress(WlLib, 'InternetGetConnectedState');
  if @GetCS <> nil then
  begin
    if GetCS(State, 0) then
    begin
      BtnCDDB.Enabled := True;
      FreeLibrary(WlLib);
    end else
    begin
      BtnCDDB.Enabled := False;
      FreeLibrary(WlLib);
    end;
  end;
end;



This is another way:

function InetIsOffline(Flag: Integer): Boolean; stdcall; external 'URL.DLL';

procedure TForm1.Button1Click(Sender: TObject);
begin
if InetIsOffline( 0 ) then
   ShowMessage( 'Computer not connected to internet' )
else
   ShowMessage( 'Computer connected to internet' );
end;



 
[Return to Top]

  
Disconnecting from ISP
Steve Williams  stevewilliams@kromestudios.com    
06/03/2001

> When using some ICS components, the method Quit() only disconnects
> from the mail server. It does not disconnect from the ISP server.
> I could not find a method to disconnect from the ISP server.

Disconnecting from the ISP is not the task of the component. If you are using RAS (Dial-Up Networking) to connect to your ISP, then use Francois' RAS.PAS (available with the RasDial application from his website) to drop the current RAS connection.

Don't forget that not everyone uses RAS for their Internet connection.

 
[Return to Top]

  
Dynamic IP address
Francois Piette francois.piette@overbyte.be    
06/03/2001

> Is there a way to connect to a server when it has a dynamic IP addresses

You cannot dialog between two computers with dynamically allocated IP addresses, no matter which program you use. You have to have another computer with a fixed IP address to serve as a common exchange point.

 
[Return to Top]

  
Getting IE settings
Wilfried Mestdagh wilfried@mestdagh.biz    
09/03/2001

> I want to be able to make my program connect to the web without the user
> having to configure all the settings. How do I get the settings of IE or
> Netscape ?

in the registry under the following key:

     HKEY_CURRENT_USER
          Software
               Microsoft
                    Windows
                         CurrentVersion
                              InternetSettings


 
[Return to Top]

  
For an MX-Lookup I need an DNS Server. Where can I find this Server?
Angus Robertson angus@magsys.co.uk    
17/12/2001

The DNS server can be found using the IP Helper APIs for Win98, WinME, W2K and XP only, other techniques are needed for Win95 and NT4.  

I used Dirk Claessens's IP Helper code from  http://www.claessens16.yucom.be/ , but had to fix some bugs that prevented dynamic DNS servers being returned, and I changed it to load the IP Helper DLL dynamically to avoid problems when it's not installed.  I sent the code to him in the summer, but he never released it. 

So my enhanced version is now part of the latest release of my RAS component, {FIXED+TMagRas that may be downloaded from  http://www.magsys.co.uk/delphi/ .  I also added extra code to get DNS servers for Win95 and NT4 (by running the winconfg program).  

Although TMasRas is shareware and only registered users get source code, all the IP Helper and DNS source code is included in the demo version, I'm not charging for it. 

 
[Return to Top]

  
How to get DNS Servers currently used?
SJF and Francois PIETTE bcb@daqing.net    
23/12/2001


To get the current fixed DNS Servers (those hard-coded in the TCP/IP network settings) you can do this:

VC++ Source:
// For WinNT
char szBuff[MAX_PATH] = {0};
GetRegString(HKEY_LOCAL_MACHINE,
            "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
            "Domain",
            szBuff,
            sizeof(szBuff)-1);
char* szYourDomain = szBuff;

//For Win98
char szBuff[MAX_PATH] = {0};
GetRegString(HKEY_LOCAL_MACHINE,
            "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP",
            "NameServer",
            szBuff,
            sizeof(szBuff)-1);
char* szYourDomain = szBuff;


Delphi Source:
with TRegistry.Create do
 try
  { Win98 }
  RootKey := HKEY_LOCAL_MACHINE;
  if OpenKey('\System\CurrentControlSet\Services\VxD\MSTCP', False) then
   begin
    FAddr_registry := ReadString('NameServer');
    CloseKey;
   end;

 finally
  Free;
 end;




If you are using more than one DNS Server, it will return them like this:
 202.97.224.68,202.96.0.133,202.96.1.133

But this code does not return any dynamically allocated DNS (such as those assigned when connected using RAS or xDSL).

To get those, you have to use IP Helper API or WinIpCfg/IpConfig utility. See IPHELPER.ZIP at Usermade webpage.

 
[Return to Top]

   

The ICS FAQ is created and maintained by the ICS VIP Documentation Effort Group.
For more information on how to join our efforts, send email to:
[ICS FAQ]