【问题标题】:Iterate through all UPnP port forward entries遍历所有 UPnP 端口转发条目
【发布时间】:2021-11-19 04:43:19
【问题描述】:

使用Port Forward using UPnP - close port 的Delphi 代码,我设法添加和删除了UPnP 端口转发条目。我对变体的经验为零,如何遍历现有条目?

【问题讨论】:

    标签: delphi


    【解决方案1】:

    我设法从找到的其他代码中弄明白了:

    uses ComObj, ActiveX;
    
    procedure ShowUPnPEntries;
    var
      Nat, Ports: Variant;
      Port: OleVariant;
      Enum: IEnumVariant;
      iValue: longword;
      Msg, Desc, ExtIP, IntClient, ProtoCol: string;
      Enabled: boolean;
      ExtPort, IntPort: integer;
    begin
      Nat := CreateOleObject('HNetCfg.NATUPnP');
      Ports := Nat.StaticPortMappingCollection;
      Msg := '';
      if not VarIsClear(Ports) then
      begin
        Enum := IUnknown(Ports._NewEnum) as IEnumVariant;
        while ENum.Next(1, Port, iValue) = 0 do
        begin
          Desc := Port.Description;
          Enabled := Port.Enabled;
          ExtIP := Port.ExternalIPAddress;
          ExtPort := Port.ExternalPort;
          IntClient := Port.InternalClient;
          IntPort := Port.InternalPort;
          Protocol := Port.Protocol;
          if Msg <> '' then Msg := Msg + #13;
          Msg := Msg + Desc + ' ' + IntToStr(ExtPort) + '/' + IntToStr(IntPort) + ' ' +
            Protocol + ' ' + ExtIP + '/' + IntClient + ' ';
          if Enabled then Msg := Msg + 'Enabled' else Msg := Msg + 'Disabled';
        end;
      end;
      ShowMessage(Msg);
    end;
    

    【讨论】:

      猜你喜欢
      • 2012-11-03
      • 2012-04-02
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 2018-01-02
      • 2013-01-07
      • 2014-08-18
      • 1970-01-01
      相关资源
      最近更新 更多