---
title: "Internet"
type: "forum-thread"
url: "https://www.webforum.nu/amne/programmering/27788-internet"
topic: "Programmering"
topic_url: "https://www.webforum.nu/amne/programmering"
author: "Niclas Ohlsson"
published: "2000-07-21T21:52:00.000Z"
updated: "2000-07-25T20:33:00.000Z"
replies: 4
views: 480
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/programmering/27788-internet"
---

# Internet

## #1 — Niclas Ohlsson, 2000-07-21T21:52Z

Hur gör man för att kolla om man är online på internet via sitt prog.

Permalänk: https://www.webforum.nu/p/27788

## #2 — Alpha II, 2000-07-22T20:54Z

Man kan kolla IP nummret (vilket jag inte vet hur man gör..) och om det är 127.0.0.1, eller nått så är man offline.

Permalänk: https://www.webforum.nu/p/400163

## #3 — bughawk, 2000-07-22T21:07Z

Det är inte bombsäkert... När jag är offline så får jag en default IP och den är inte 127.0.0.1... Jag skulle tro att windows erbjuder någon standardfunktion för att testa huruvida man är online...

Permalänk: https://www.webforum.nu/p/400164

## #4 — Alpha II, 2000-07-23T17:51Z

Den här koden hittade jag på [www.torrys.ru](http://www.torrys.ru) 
\<font size="1" face="Verdana, Arial, Helvetica, sans-serif"\>Kod:\<font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#666600"\>
interface  
uses  
  Windows, SysUtils, Registry, WinSock, WinInet;  

type  
  TConnectionType = (ctNone, ctProxy, ctDialup);  

function ConnectedToInternet : TConnectionType;  
function RasConnectionCount : Integer;  
   

implementation  

//For RasConnectionCount =======================  
const  
  cERROR_BUFFER_TOO_SMALL = 603;  
  cRAS_MaxEntryName       =  256;  
  cRAS_MaxDeviceName      =  128;  
  cRAS_MaxDeviceType      =  16;  
type  
  ERasError = class(Exception);  

  HRASConn = DWord;  
  PRASConn = ^TRASConn;  
  TRASConn = record  
     dwSize: DWORD;  
     rasConn: HRASConn;  
     szEntryName: Array\[0..cRAS_MaxEntryName\] Of Char;  
     szDeviceType : Array\[0..cRAS_MaxDeviceType\] Of Char;  
     szDeviceName : Array \[0..cRAS_MaxDeviceName\] of char;  
  end;  

  TRasEnumConnections =  
      function (RASConn: PrasConn; { buffer to receive Connections data }  
                var BufSize: DWord;    { size in bytes of buffer }  
                var Connections: DWord { number of Connections written to buffer }  
                ): LongInt; stdcall;  
//End RasConnectionCount =======================  
   

function ConnectedToInternet: TConnectionType;  
var  
  Reg       : TRegistry;  
  bUseProxy : Boolean;  
  UseProxy  : LongWord;  
begin  
  Result := ctNone;  
  Reg := TRegistry.Create;  
  with REG do  
  try  
    try  
      RootKey := HKEY_CURRENT_USER;  
      if OpenKey('\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet settings',False) then begin  
        //I just try to read it, and trap an exception  
        if GetDataType('ProxyEnable') = rdBinary then  
          ReadBinaryData('ProxyEnable', UseProxy, SizeOf(LongWord) )  
        else begin  
          bUseProxy := ReadBool('ProxyEnable');  
          if bUseProxy then  
            UseProxy := 1  
          else  
            UseProxy := 0;  
        end;  
        if (UseProxy \<\> 0) and ( ReadString('ProxyServer') \<\> '' ) then Result := ctProxy;  
      end;  
    except  
      //Obviously not connected through a proxy  
    end;  
  finally  
    Free;  
  end;  

  //We can check RasConnectionCount even if dialup networking is not installed  
  //simply because it will return 0 if the DLL is not found.  
  if Result = ctNone then begin  
    if RasConnectionCount \> 0 then Result := ctDialup;  
  end;  
end;  

function RasConnectionCount : Integer;  
var  
  RasDLL    : HInst;  
  Conns     : Array\[1..4\] of TRasConn;  
  RasEnums  : TRasEnumConnections;  
  BufSize   : DWord;  
  NumConns  : DWord;  
  RasResult : Longint;  
begin  
  Result := 0;  

  //Load the RAS DLL  
  RasDLL := LoadLibrary('rasapi32.dll');  
  if RasDLL = 0 then exit;  

  try  
    RasEnums := GetProcAddress(RasDLL,'RasEnumConnectionsA');  
    if @RasEnums = nil then  
      raise ERasError.Create('RasEnumConnectionsA not found in rasapi32.dll');  

    Conns\[1\].dwSize := Sizeof (Conns\[1\]);  
    BufSize := SizeOf(Conns);  

    RasResult := RasEnums(@Conns, BufSize, NumConns);  

    If (RasResult = 0) or (Result = cERROR_BUFFER_TOO_SMALL) then Result := NumConns;  
  finally  
    FreeLibrary(RasDLL);  
  end;  
end;

Permalänk: https://www.webforum.nu/p/400165

## #5 — Niclas Ohlsson, 2000-07-25T20:33Z

Jag får inte koden att fungera.

Hur ser HELA koden ut??

Permalänk: https://www.webforum.nu/p/400166

---

Tråden på webben: https://www.webforum.nu/amne/programmering/27788-internet
