Delphi,如何获取所有本地 IP? [英] Delphi, How to get all local IPs?

查看:32
本文介绍了Delphi,如何获取所有本地 IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道在 delphi 中获取本地 ip 地址的简单列表(例如 tstrings)的方法.

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

我查看了另一个相关问题,但似乎无法将它们转换为 delphi.

I have had a look at the other related question, and cant seem to get my head around converting them to delphi.

推荐答案

在indy 9中,有一个单元IdStack,类为TIdStack

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;

效果很好:)

来自 Remy Lebeau 的评论

from Remy Lebeau's Comment

同样存在于 Indy 10 中,但是代码有点不同:

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; 

这篇关于Delphi,如何获取所有本地 IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆