tracert 公网IP不显示经过的局域网IP
时间: 2024-04-09 10:30:07 浏览: 30
tracert 命令用于追踪数据包从源IP地址到目标IP地址的路径。默认情况下,它只显示经过的公网IP地址,不会显示经过的局域网IP地址。
这是因为局域网IP地址通常是私有地址,不会在公共互联网上路由。当数据包从局域网中的计算机发送到公网时,路由器会将源IP地址替换为公网IP地址,并在传输过程中隐藏局域网IP地址。
所以,当你使用 tracert 命令时,你只能看到经过的公网IP地址,而看不到局域网IP地址。
相关问题
QT5.6 提取 tracert 的IP地址
要提取 tracert 的 IP 地址,你可以通过以下步骤:
1. 在 QT 5.6 中使用 QProcess 类启动 tracert 命令,例如:
```
QProcess process;
process.start("tracert www.google.com");
process.waitForFinished();
QString output = process.readAllStandardOutput();
```
2. 解析 tracert 命令的输出,提取其中的 IP 地址。可以使用正则表达式来匹配 IP 地址,例如:
```
QRegExp rx("(\\d{1,3}\\.){3}\\d{1,3}");
QStringList ipList;
int pos = 0;
while ((pos = rx.indexIn(output, pos)) != -1) {
ipList << rx.cap(0);
pos += rx.matchedLength();
}
```
这样,ipList 中就会包含 tracert 命令输出中提取到的所有 IP 地址。
powerbuilder中获取公网ip
在PowerBuilder中,要获取公网IP地址,可以通过以下方式:
1. 使用Web Service:使用公共Web服务如ipinfo.io或ip-api.com。这些Web服务提供了API,可以返回访问者的IP地址和相关信息。您可以使用PowerBuilder的SOAP客户端对象或WSCLIENT对象来访问这些Web服务,并从响应中提取IP地址。
2. 使用INET库函数:PowerBuilder的INET库函数提供了许多与因特网通信相关的功能,例如ping、tracert和获取IP地址。您可以使用inet.gethostname函数来获取本地主机名,然后使用inet.gethostbyname函数来获取公网IP地址。
3. 使用Windows API:您还可以使用Windows API函数来获取公网IP地址。例如,您可以使用GetAdaptersAddresses函数来检索系统上的所有网络适配器的信息,然后从中找到具有Internet连接和公网IP地址的适配器。
需要注意的是,使用公共Web服务可能会受到访问限制,而获取IP地址和网络信息的方法可能随操作系统和网络环境的不同而不同。因此,在实施这些方法之前,需要进行相关的测试和验证。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)