void vAdjustIP(std::string& paraStrIP)
{
std::string strTemp[5] ;
int i = 0 ;
strTemp[i] = strtok((char*)paraStrIP.c_str(), ".") ;
while (!strTemp[i].empty())
{
// 进行处理
if (1 == strTemp[i].size())
{
strTemp[i].insert(0, 2, '0') ;
}
else if (2 == strTemp[i].size())
{
strTemp[i].insert(0, 1, '0') ;
}
if (3 == i)
{// 因为最后返回的是NULL,而string不能接收NULL参数,所以就此跳出
break ;
}
strTemp[++i] = strtok(NULL, ".") ;
}
paraStrIP.erase() ;
for (i = 0; i < 4; ++i)
{
paraStrIP += strTemp[i] ;
if (3 != i)
{
paraStrIP += "." ;
}
}
}
// 判断地址是否为内网地址
// 内网地址有三种呈现形式
// 1. 10.X.X.X
// 2. 172.16.X.X 到 172.31.X.X
// 3. 192.168.XX
// 注:传进来的strIP必须是 XXX.XXX.XXX.XXX 格式,必须保留三,这是为了方便比较
BOOL fIsInnerIp(const std::string& strIP)
{
std::string str10From("010.000.000.0000") ;
std::string str10To("010.255.255.255") ;
std::string str172From("172.016.000.000") ;
std::string str172To("172.031.000.000") ;
std::string str192From("192.168.000.000") ;
std:;string str192To("192.168.255.255") ;
std::string strIPTemp = strIP ;
vAdjustIP(strIPTemp) ;
if (strIPTemp >= str10From && strIPTemp <= str10To)
{
return TRUE ;
}
else if (strIPTemp >= str172From && strIPTemp <= str172To)
{
return TRUE ;
}
else if(strIPTemp >= str192From && strIPTemp <= str192To)
{
return TRUE ;
}
return FALSE ;
}