📄 anaip.cpp
字号:
// anaIP.cpp: implementation of the anaIP class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "range.h"
#include "anaIP.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
anaIP::anaIP()
{
for(int i=0;i<4;i++)
{
start[i]=0;
end[i]=0;
num[i]=0;
}
}
anaIP::~anaIP()
{
}
BOOL anaIP::GetIP(CString fromIP,CString toIP)
{
int i,j,k;
int Count;
char temp[3];
LPTSTR from=NULL;
LPTSTR to=NULL;
from=fromIP.GetBuffer(16);
to=toIP.GetBuffer(16);
if(IsCorrectIP(fromIP)==FALSE)
{
MessageBox(GetFocus(),"illegal IP!","wrong",MB_OK);
return FALSE;
}
if(IsCorrectIP(toIP)==FALSE)
{
MessageBox(GetFocus(),"illegal IP!","wrong",MB_OK);
return FALSE;
}
Count=fromIP.GetLength();
from[Count]='.';
for(i=0,j=0,k=0;i<(Count+1);i++)
{
if(from[i]=='.')
{
start[j]=atoi(temp);
j++;
k=0;
continue;
}
if(k>3)
{
MessageBox(GetFocus(),"illegal IP!","wrong",MB_OK);
return FALSE;
}
if(k==0)
{
temp[0]=0;
temp[1]=0;
temp[2]=0;
}
else
temp[k]=temp[k-1];
temp[k]=from[i];
k++;
}
Count=toIP.GetLength();
to[Count]='.';
for(i=0,j=0,k=0;i<(Count+1);i++)
{
if(to[i]=='.')
{
end[j]=atoi(temp);
j++;
k=0;
continue;
}
if(k>3)
{
MessageBox(GetFocus(),"illegal IP!","wrong",MB_OK);
return FALSE;
}
if(k==0)
{
temp[0]=0;
temp[1]=0;
temp[2]=0;
}
else
temp[k]=temp[k-1];
temp[k]=to[i];
k++;
}
fromIP.ReleaseBuffer();
toIP.ReleaseBuffer();
return TRUE;
}
BOOL anaIP::IsCorrectIP(CString IP)
{
int Count;
char* ip=NULL;
Count = IP.GetLength();
if(Count > 15)
return FALSE;
ip = IP.GetBuffer(15);
for(int i=0;i<Count;i++)
{
if(ip[i]=='.')
continue;
if(ip[i] < 47 || ip[i] > 58)
return FALSE;
}
IP.ReleaseBuffer();
return TRUE;
}
int anaIP::ComputeHostNum()
{
hostnum=0;
for(int i=0;i<4;i++)
{
num[i]=0;
}
for(i=0;i<4;i++)
{
if(start[i]>254)
start[i]=254;
if(end[i]>254)
end[i]=254;
num[i]=end[i]-start[i];
}
hostnum=1+num[3]+num[2]*254+num[1]*255*254+num[0]*255*255*254;
return hostnum;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -