如何从远程计算机获取IP地址

如何从远程计算机获取IP地址

本文介绍了如何从远程计算机获取IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写的c ++代码,我需要在Windows和linux上运行,我正在寻找一个函数调用,将返回的应用程序运行的框的IP地址。有这样一个吗?

解决方案

你可以做到,但它通常是一个坏主意。



ioctl SIOCGIFCONF如man netdevice中所述。



这是一个坏主意的原因是你可能不会得到你想要的东西。



机器可以有几个或许多IP地址,你不知道哪个是
public。它可能在一个NAT网关(或几个)后面,在这种情况下,它们都不能是public的。$ / b>

你不能使用那个信息特别有用。无论你想要什么,它的
可能不是一个好主意。


I'm writing c++ code that I need to run on both windows and linux and I'm looking for a function call that will return the ip address of the box the app is running on. Is there such one?

解决方案

You can do it but it's generally a bad idea.

ioctl SIOCGIFCONF as described in "man netdevice" explains this.

The reason it's a bad idea is that you probably won't get what you want out of it.

The machine could have several or many IP addresses, you won't know which one(s) arepublic. It could be behind a NAT gateway (or several) in which case none of themmay be public.

You just can't use that info particularly usefully. Whatever you want it for, it'sprobably not a good idea to do it.

这篇关于如何从远程计算机获取IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:30