获取全局ip地址 [英] get global ip address

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

问题描述

如何获得(在C ++中)我的计算机的全局 IP地址(Windows XP)?

How can I get ( in C++ ) the global IP address of my computer(windows XP)?

推荐答案

您不能。

您可以确定各种接口上的IP地址,并且可能有多个。这些可能是局域网IP(10.0.0.0/8,192.168.0.0/16等),或者他们可能是互联网可路由的。

You can determine the IP addresses on the various interfaces, and there may be more than one. These could be local area network IPs (10.0.0.0/8, 192.168.0.0/16, etc.), or they might be internet routable.

你似乎是问如果我有192.168.0.3,如何获得我的互联网IP?没有函数调用来做到这一点:这样的IP可能存在,它可能不存在,甚至可能有一个以上。

You seem to be asking "if I have 192.168.0.3, how do I get my Internet IP?" There is not function call to do this: such an IP might exist, it might not exist, there might even be more than one.

你可以得到的最接近的是有一个已知的计算机在互联网上告诉你:连接到一些其他机器,并要求他们发回他们认为你的IP地址是什么。这里有几个网站,有些甚至可以有API来做到这一点。

The closest you can get is to have a known computer on the Internet tell you: connect to some other machine, and ask them to send back what they think your IP address is. There are a few websites out there for this, some might even have APIs to do this.

我觉得一些家庭路由器可能也能告诉你通过uPnP ,但同样,这不会涵盖所有可能的情况。

I feel like some home-routers might be able to tell you through uPnP too, but again, this will not cover all possible cases.

这篇关于获取全局ip地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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