Board index » delphi » Problem on detecting internet connection

Problem on detecting internet connection

the component i am using sends/receives a event when i am logged into my
IPS, meaning after sending username and password and waiting for the ISP to
confirm my TCP/IP connection.
Bus as I am trying to develop a phone-cost tracking app I need to detect
connection even before logging in. So I need an event to occur when the
noice through the modem speaker starts , when the other side picks up the
call.

Anyone heaving any idea's?

Also welcome:

Stuff about fingering
Stuff about starting and stopping an Internet connection, and getting all
possible Internet connections on the machine.

Thanks.,
Rik

 

Re:Problem on detecting internet connection


In article <7f5j28$ts...@enterprise.cistron.nl>, ruse...@bigfoot.com says...

Quote
>the component i am using sends/receives a event when i am logged into my
>IPS, meaning after sending username and password and waiting for the ISP to
>confirm my TCP/IP connection.
>Bus as I am trying to develop a phone-cost tracking app I need to detect
>connection even before logging in. So I need an event to occur when the
>noice through the modem speaker starts , when the other side picks up the
>call.

Well, here's some code from one of my apps. I first try
rasapi32/RasEnumConnections, and then wininet/InternetGetConnectedState.
I doesnt trigger an event but you can call it from a timer event
every few secs or so, to detect connection/disconnection.

Regards/Stefan
Please find e-mail address here:
http://home.swipnet.se/align/shareware

@@@@@@@@@@@@@@@@  U  R  L  S  E  N  T  R  Y  @@@@@@@@@@@@@@@@@@@@@@@@@@

Get Instant Notification of Changes or Updates of Your Favourite Sites!
Free Download Here:

  http://home.swipnet.se/align/shareware

URLSentry is a Windows shareware application that can be used
to monitor changes in any Web Pages of interest to you.
It runs silently in the system tray, instantly alerting you to
any Web Page Changes or Updates detected.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

var RasEnumConnections:
      function (
        rasconnArray: LPRasConn;
        var lpcb: Longint;
        var lpcConnections: Longint
      ): Longint; stdcall;

var InternetGetConnectedState:
  function (lpdwFlags: LPDWORD;
  dwReserved: DWORD): BOOL; stdcall;

function InetConnected(bAutoCheck:boolean):boolean;
  var
    bufsize: Longint;
    numEntries: Longint;
    entries: Array[1..32] of TRasConn;
    stat: TRasConnStatus;
    flags,dummy:longint;
    hRasApi,hWinInet:tHandle;
begin
  InetConnected:= true;
  hRasApi:= LoadLibrary('rasapi32');
  if hRasApi<>0 then
  begin
    RasEnumConnections:= GetProcAddress(hRasApi,'RasEnumConnectionsA');
    if @RasEnumConnections<>nil then
    begin
      entries[1].dwSize := SizeOf(TRasConn);
      bufsize := SizeOf(TRasConn) * 30;
      FillChar(stat, Sizeof(TRasConnStatus), 0);
      stat.dwSize := Sizeof(TRasConnStatus);
      if RasEnumConnections(@entries[1], bufsize, numEntries) = 0 then
        if numEntries > 0 then begin freeLibrary(hRasApi);
                                     InetConnected:= true;
                                     exit;
                               end;
    end;
    freeLibrary(hRasApi);
  end;
  dummy:= 0;
  hWinInet:= LoadLibrary('wininet');
  if hWinInet<>0 then
  begin
    InternetGetConnectedState:= GetProcAddress(hWininet,
'InternetGetConnectedState');
    if @InternetGetConnectedState<>nil then
    begin
      if InternetGetConnectedState(@flags,dummy) then
      begin freeLibrary(hWinInet);
            InetConnected:= true;
            exit;
      end;
    end;
    freeLibrary(hWinInet);
  end;
  InetConnected:= false;
end;

Re:Problem on detecting internet connection


Alternatively you could check to see if DUN is running. Possibly?

Align Software AB <ForEMailAddr...@SeeOurWebPage.com> wrote:

Quote

>In article <7f5j28$ts...@enterprise.cistron.nl>, ruse...@bigfoot.com says...
>>the component i am using sends/receives a event when i am logged into my
>>IPS, meaning after sending username and password and waiting for the ISP to
>>confirm my TCP/IP connection.
>>Bus as I am trying to develop a phone-cost tracking app I need to detect
>>connection even before logging in. So I need an event to occur when the
>>noice through the modem speaker starts , when the other side picks up the
>>call.

>Well, here's some code from one of my apps. I first try
>rasapi32/RasEnumConnections, and then wininet/InternetGetConnectedState.
>I doesnt trigger an event but you can call it from a timer event
>every few secs or so, to detect connection/disconnection.

>Regards/Stefan
>Please find e-mail address here:
>http://home.swipnet.se/align/shareware

>@@@@@@@@@@@@@@@@  U  R  L  S  E  N  T  R  Y  @@@@@@@@@@@@@@@@@@@@@@@@@@

>Get Instant Notification of Changes or Updates of Your Favourite Sites!
>Free Download Here:

>  http://home.swipnet.se/align/shareware

>URLSentry is a Windows shareware application that can be used
>to monitor changes in any Web Pages of interest to you.
>It runs silently in the system tray, instantly alerting you to
>any Web Page Changes or Updates detected.

>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

>var RasEnumConnections:
>      function (
>        rasconnArray: LPRasConn;
>        var lpcb: Longint;
>        var lpcConnections: Longint
>      ): Longint; stdcall;

>var InternetGetConnectedState:
>  function (lpdwFlags: LPDWORD;
>  dwReserved: DWORD): BOOL; stdcall;

>function InetConnected(bAutoCheck:boolean):boolean;
>  var
>    bufsize: Longint;
>    numEntries: Longint;
>    entries: Array[1..32] of TRasConn;
>    stat: TRasConnStatus;
>    flags,dummy:longint;
>    hRasApi,hWinInet:tHandle;
>begin
>  InetConnected:= true;
>  hRasApi:= LoadLibrary('rasapi32');
>  if hRasApi<>0 then
>  begin
>    RasEnumConnections:= GetProcAddress(hRasApi,'RasEnumConnectionsA');
>    if @RasEnumConnections<>nil then
>    begin
>      entries[1].dwSize := SizeOf(TRasConn);
>      bufsize := SizeOf(TRasConn) * 30;
>      FillChar(stat, Sizeof(TRasConnStatus), 0);
>      stat.dwSize := Sizeof(TRasConnStatus);
>      if RasEnumConnections(@entries[1], bufsize, numEntries) = 0 then
>        if numEntries > 0 then begin freeLibrary(hRasApi);
>                                     InetConnected:= true;
>                                     exit;
>                               end;
>    end;
>    freeLibrary(hRasApi);
>  end;
>  dummy:= 0;
>  hWinInet:= LoadLibrary('wininet');
>  if hWinInet<>0 then
>  begin
>    InternetGetConnectedState:= GetProcAddress(hWininet,
>'InternetGetConnectedState');
>    if @InternetGetConnectedState<>nil then
>    begin
>      if InternetGetConnectedState(@flags,dummy) then
>      begin freeLibrary(hWinInet);
>            InetConnected:= true;
>            exit;
>      end;
>    end;
>    freeLibrary(hWinInet);
>  end;
>  InetConnected:= false;
>end;

...and stuff.
--  
seb http://mapform.gibbed.com/ 24078244
 "in wigan, a kebab is a pie on a stick"
  - peterb

Re:Problem on detecting internet connection


just wanted to say thanks for the code. it reminded me that the rasapi32 had to
be checked for and not assumed. all functions called use getprocaddress...
anyway if you are calling your function periodically as written, you need to
change it. loadlibrary should only be done once. loading & unloading wastes a
tremendous amount of resources and cpu time...

On Sun, 18 Apr 1999 14:26:37 GMT, ForEMailAddr...@SeeOurWebPage.com (Align

Quote
Software AB) wrote:

>In article <7f5j28$ts...@enterprise.cistron.nl>, ruse...@bigfoot.com says...
>>the component i am using sends/receives a event when i am logged into my
>>IPS, meaning after sending username and password and waiting for the ISP to
>>confirm my TCP/IP connection.
>>Bus as I am trying to develop a phone-cost tracking app I need to detect
>>connection even before logging in. So I need an event to occur when the
>>noice through the modem speaker starts , when the other side picks up the
>>call.

>Well, here's some code from one of my apps. I first try
>rasapi32/RasEnumConnections, and then wininet/InternetGetConnectedState.
>I doesnt trigger an event but you can call it from a timer event
>every few secs or so, to detect connection/disconnection.

>Regards/Stefan
>Please find e-mail address here:
>http://home.swipnet.se/align/shareware

>@@@@@@@@@@@@@@@@  U  R  L  S  E  N  T  R  Y  @@@@@@@@@@@@@@@@@@@@@@@@@@

>Get Instant Notification of Changes or Updates of Your Favourite Sites!
>Free Download Here:

>  http://home.swipnet.se/align/shareware

>URLSentry is a Windows shareware application that can be used
>to monitor changes in any Web Pages of interest to you.
>It runs silently in the system tray, instantly alerting you to
>any Web Page Changes or Updates detected.

>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

>var RasEnumConnections:
>      function (
>        rasconnArray: LPRasConn;
>        var lpcb: Longint;
>        var lpcConnections: Longint
>      ): Longint; stdcall;

>var InternetGetConnectedState:
>  function (lpdwFlags: LPDWORD;
>  dwReserved: DWORD): BOOL; stdcall;

>function InetConnected(bAutoCheck:boolean):boolean;
>  var
>    bufsize: Longint;
>    numEntries: Longint;
>    entries: Array[1..32] of TRasConn;
>    stat: TRasConnStatus;
>    flags,dummy:longint;
>    hRasApi,hWinInet:tHandle;
>begin
>  InetConnected:= true;
>  hRasApi:= LoadLibrary('rasapi32');
>  if hRasApi<>0 then
>  begin
>    RasEnumConnections:= GetProcAddress(hRasApi,'RasEnumConnectionsA');
>    if @RasEnumConnections<>nil then
>    begin
>      entries[1].dwSize := SizeOf(TRasConn);
>      bufsize := SizeOf(TRasConn) * 30;
>      FillChar(stat, Sizeof(TRasConnStatus), 0);
>      stat.dwSize := Sizeof(TRasConnStatus);
>      if RasEnumConnections(@entries[1], bufsize, numEntries) = 0 then
>        if numEntries > 0 then begin freeLibrary(hRasApi);
>                                     InetConnected:= true;
>                                     exit;
>                               end;
>    end;
>    freeLibrary(hRasApi);
>  end;
>  dummy:= 0;
>  hWinInet:= LoadLibrary('wininet');
>  if hWinInet<>0 then
>  begin
>    InternetGetConnectedState:= GetProcAddress(hWininet,
>'InternetGetConnectedState');
>    if @InternetGetConnectedState<>nil then
>    begin
>      if InternetGetConnectedState(@flags,dummy) then
>      begin freeLibrary(hWinInet);
>            InetConnected:= true;
>            exit;
>      end;
>    end;
>    freeLibrary(hWinInet);
>  end;
>  InetConnected:= false;
>end;

Re:Problem on detecting internet connection


Quote
z...@oisin.demon.co.uk wrote:
>On Mon, 19 Apr 1999 00:03:42 +0100, seb mackie <s...@{*word*30}you.co.uk>
>wrote:

>>Alternatively you could check to see if DUN is running. Possibly?

>DUN <> Internet connection for those who have internet access through
>a LAN.

>Noel

Oh yeah, didn't think of that. Oops.

Surely another program will be running though, hidden possibly?

...and stuff.
--  
seb http://mapform.gibbed.com/ 24078244
 "in wigan, a kebab is a pie on a stick"
  - peterb

Other Threads