Format
Delphi
Post date
2019-06-28 02:21
Publication Period
Unlimited
  1. unit Unit1;
  2. {
  3. 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.
  4. }
  5. interface
  6. uses
  7. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8. Dialogs, ExtCtrls, StdCtrls, NETWORKLIST_TLB;
  9. type
  10. TForm1 = class(TForm)
  11. TIMR: TTimer;
  12. LABE: TLabel;
  13. procedure FormCreate(Sender: TObject);
  14. procedure TIMRTimer(Sender: TObject);
  15. private
  16. { Private declarations }
  17. FNLM: INetworkListManager;
  18. public
  19. { Public declarations }
  20. end;
  21. var
  22. Form1: TForm1;
  23. implementation
  24. {$R *.dfm}
  25. procedure TForm1.FormCreate(Sender: TObject);
  26. begin
  27. FNLM := CoNetworkListManager.Create;
  28. end;
  29. function TranslateConnectivity(Connectivity : NLM_CONNECTIVITY) : string;
  30. begin
  31. Result := '';
  32. with TStringList.Create do
  33. try
  34. if NLM_CONNECTIVITY_DISCONNECTED and Connectivity <> 0 then
  35. Add('Não conectado a nenhuma rede');
  36. if NLM_CONNECTIVITY_IPV4_NOTRAFFIC and Connectivity <> 0 then
  37. Add('Conectado, mas sem tráfego ipv4');
  38. if NLM_CONNECTIVITY_IPV6_NOTRAFFIC and Connectivity <> 0 then
  39. Add('Conectado, mas sem tráfego ipv6');
  40. if NLM_CONNECTIVITY_IPV4_SUBNET and Connectivity <> 0 then
  41. Add('Há conectividade a uma subrede local via ipv4');
  42. if NLM_CONNECTIVITY_IPV4_LOCALNETWORK and Connectivity <> 0 then
  43. Add('Há conectividade a uma rede local via ipv4');
  44. if NLM_CONNECTIVITY_IPV4_INTERNET and Connectivity <> 0 then
  45. Add('Há conectividade coma a Internet via ipv4');
  46. if NLM_CONNECTIVITY_IPV6_SUBNET and Connectivity <> 0 then
  47. Add('Há conectividade a uma subrede local via ipv6');
  48. if NLM_CONNECTIVITY_IPV6_LOCALNETWORK and Connectivity <> 0 then
  49. Add('Há conectividade a uma rede local via ipv6');
  50. if NLM_CONNECTIVITY_IPV6_INTERNET and Connectivity <> 0 then
  51. Add('Há conectividade coma a Internet via ipv6');
  52. Result := Text;
  53. finally
  54. Free;
  55. end;
  56. end;
  57. procedure TForm1.TIMRTimer(Sender: TObject);
  58. begin
  59. LABE.Caption := TranslateConnectivity(FNLM.GetConnectivity);
  60. end;
  61. end.
다운로드 Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text