获取本地计算机的IP地址 [英] Get the IP Address of local computer

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

问题描述

在C ++中,获取本地计算机的IP地址和子网掩码最简单的方法是什么?

In C++, what's the easiest way to get the local computer's IP address and subnet mask?

我想要能够检测本地计算机的IP地址本地网络。在我的特殊情况下,我有一个网络的子网掩码为255.255.255.0,我的计算机的IP地址是192.168.0.5。我需要获得这两个值以编程方式为了发送广播消息到我的网络(在形式192.168.0.255,对于我的特殊情况)

I want to be able to detect the local machine's IP address in my local network. In my particular case, I have a network with a subnet mask of 255.255.255.0 and my computer's IP address is 192.168.0.5. I need to get these had two values programmatically in order to send a broadcast message to my network (in the form 192.168.0.255, for my particular case)

编辑:多答案没有给出我预期的结果,因为我有两个不同的网络IP。 Torial 的代码做了伎俩(它给了我两个IP地址)。谢谢。

Many answers were not giving the results I expected because I had two different network IP's. Torial's code did the trick (it gave me both IP addresses). Thanks.

编辑2:感谢

Edit 2: Thanks to Brian R. Bondy for the info about the subnet mask.

推荐答案

如果您使用winsock,这里有一种方法: http://tangentsoft.net/wskfaq/examples/ipaddr.html

If you use winsock, here's a way: http://tangentsoft.net/wskfaq/examples/ipaddr.html

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

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