Delphi, How to get all local IPs?

前端 未结 6 1677
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 07:47

Any one know a way in delphi get a simple list (eg tstrings) of the local ip address.

I have had a look at the other related question, and cant seem to get my head a

6条回答
  •  天涯浪人
    2020-12-03 08:19

    in indy 9, there is a unit IdStack, with the class TIdStack

    fStack := TIdStack.CreateStack;
    try
      edit.caption := fStack.LocalAddress;  //the first address i believe
      ComboBox1.Items.Assign(fStack.LocalAddresses); //all the address'
    finally
      freeandnil(fStack); 
    end;
    

    works great :)

    from Remy Lebeau's Comment

    The same exists in Indy 10, but the code is a little different:

    TIdStack.IncUsage; 
    try 
      GStack.AddLocalAddressesToList(ComboBox1.Items); 
      Edit.Caption := ComboBox1.Items[0]; 
    finally 
      TIdStack.DecUsage; 
    end; 
    

提交回复
热议问题