- unit Unit1;
- {
- Primeiro importe a biblioteca de tipo Network List Manager 1.0 Type Library (netprofm.dll). Isso pode ser feito direto no Delphi via Component > Install Component, selecionando a opção "Import a Type Library" e clicando em Next. Ao final, será gerado um arquivo de nome NETWORKLIST_TLB.PAS o qual pode ser incluído no seu projeto. O código atual é de um simples TForm com um TTimer e um TLabel.
- }
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, StdCtrls, NETWORKLIST_TLB;
- type
- TForm1 = class(TForm)
- TIMR: TTimer;
- LABE: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure TIMRTimer(Sender: TObject);
- private
- { Private declarations }
- FNLM: INetworkListManager;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FNLM := CoNetworkListManager.Create;
- end;
- function TranslateConnectivity(Connectivity : NLM_CONNECTIVITY) : string;
- begin
- Result := '';
- with TStringList.Create do
- try
- if NLM_CONNECTIVITY_DISCONNECTED and Connectivity <> 0 then
- Add('Não conectado a nenhuma rede');
- if NLM_CONNECTIVITY_IPV4_NOTRAFFIC and Connectivity <> 0 then
- Add('Conectado, mas sem tráfego ipv4');
- if NLM_CONNECTIVITY_IPV6_NOTRAFFIC and Connectivity <> 0 then
- Add('Conectado, mas sem tráfego ipv6');
- if NLM_CONNECTIVITY_IPV4_SUBNET and Connectivity <> 0 then
- Add('Há conectividade a uma subrede local via ipv4');
- if NLM_CONNECTIVITY_IPV4_LOCALNETWORK and Connectivity <> 0 then
- Add('Há conectividade a uma rede local via ipv4');
- if NLM_CONNECTIVITY_IPV4_INTERNET and Connectivity <> 0 then
- Add('Há conectividade coma a Internet via ipv4');
- if NLM_CONNECTIVITY_IPV6_SUBNET and Connectivity <> 0 then
- Add('Há conectividade a uma subrede local via ipv6');
- if NLM_CONNECTIVITY_IPV6_LOCALNETWORK and Connectivity <> 0 then
- Add('Há conectividade a uma rede local via ipv6');
- if NLM_CONNECTIVITY_IPV6_INTERNET and Connectivity <> 0 then
- Add('Há conectividade coma a Internet via ipv6');
- Result := Text;
- finally
- Free;
- end;
- end;
- procedure TForm1.TIMRTimer(Sender: TObject);
- begin
- LABE.Caption := TranslateConnectivity(FNLM.GetConnectivity);
- end;
- end.