如何在Delphi中获取外部(公共)IP
I need to get my external (public) IP address from Delphi.
The same IP that is shown by www.whatismyip.com for example.
How can I do that ? Winsock doesn't allow this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用此网站:http://ipinfo.io/json。它以
JSON
格式返回有关您当前互联网连接的信息。在delphi中,您需要这样使用
IdHTTP
:IdHTTP1.Get('http://ipinfo.io/json')
它将返回一个包含所有数据的字符串。您可以使用您喜欢的
JSON
解释器,也可以使用lkJSON
,如下例:希望对您有所帮助。
You can use this website: http://ipinfo.io/json. It returns the information about your current internet connection in
JSON
format.In delphi you need use
IdHTTP
this way:IdHTTP1.Get('http://ipinfo.io/json')
and it will returns a string with all the data. You can use a
JSON
interpreter you like or you can use thelkJSON
as the following example:I hope help you.
我认为你不能。好吧,您可以调用一些服务来告诉您您的 IP 地址是什么(例如:http://www.whatismyip .com/ )并从响应中找出答案。但我认为您的 PC 上的任何内容都无法向外界透露您的 IP 地址。
未经测试,但我认为您可以使用 Indy 做到这一点:
请查看规则/政策:http:// /www.whatismyip.com/faq/automation.asp 在使用之前。
I don't think you can. Well, you could call some service that tells you what your IP address appears to be, ( ex: http://www.whatismyip.com/ ) and figure it out from the response. But I don't think anything on your PC will be able to tell you what your IP address looks like, to the outside world.
Untested, but I think you can do this with Indy:
Please review the rules/policy at: http://www.whatismyip.com/faq/automation.asp before using this.
这对我有用:
this works for me:
凭记忆,未经测试:
From memory, untested: