判断ip 是内网外网 c++

C++ 判断IP是否属于局域网IP_哈士奇超帅的博客-CSDN博客

#include <string>
#include <iostream>
#include <sstream>
 
using namespace std;
 
bool isLAN(const string& ip);
 
int main()
{
	cout<<isLAN("192.168.1.1");
	cout<<isLAN("10.1.1.1");
	cout<<isLAN("172.18.2.2");
	cout<<isLAN("3.3.3.3");
	return 0;
}
 
/*-----------------------------------------
局域网IP地址范围
A类:10.0.0.0-10.255.255.255
B类:172.16.0.0-172.31.255.255 
C类:192.168.0.0-192.168.255.255
-------------------------------------------*/
bool isLAN(const string& ipstring)
{
	istringstream st(ipstring);
	int ip[2];
	for(int i = 0; i < 2; i++)
	{
		string temp;
		getline(st,temp,'.');
		istringstream a(temp);
		a >> ip[i];
	}
	if((ip[0]==10) || (ip[0]==172 && ip[1]>=16 && ip[1]<=31) || (ip[0]==192 && ip[1]==168))
		return true;
	else return false;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值