1、在網(wǎng)站的跟路徑下面添加 QQWry.dat 文件,這個(gè)文件是IP數(shù)據(jù)庫文件
2、添加以下一個(gè)類 IPScanner
C# 代碼 復(fù)制public class IPScanner
{
//私有成員#region 私有成員
PRivate string dataPath;
private string ip;
private string country;
private string local;
private long firstStartIp = 0;
private long lastStartIp = 0;
private FileStream objfs = null;
private long startIp = 0;
private long endIp = 0;
private int countryFlag = 0;
private long endIpOff = 0;
private string errMsg = null;
//構(gòu)造函數(shù)#region 構(gòu)造函數(shù)
public IPScanner()
{
this.dataPath = System.Web.HttpContext.Current.Server.MapPath("/ipdata/QQWry.dat");
}
//公共屬性#region 公共屬性
public string DataPath
{
set { dataPath = value; }
}
public string IP
{
set { ip = value; }
}
public string Country
{
get { return country; }
}
public string Local
{
get { return local; }
}
public string ErrMsg
{
get { return errMsg; }
}
//搜索匹配數(shù)據(jù)#region 搜索匹配數(shù)據(jù)
private int QQwry()
{
string pattern = @"(((//d{1,2})|(1//d{2})|(2[0-4]//d)|(25[0-5]))//.){3}((//d{1,2})|(1//d{2})|(2[0-4]//d)|(25[0-5]))";
Regex objRe = new Regex(pattern);
Match objMa = objRe.Match(ip);
if (!objMa.Success)
{
this.errMsg = "IP格式錯(cuò)誤";
return 4;
}
long ip_Int = this.IpToInt(ip);
int nRet = 0;
if (ip_Int >= IpToInt("127.0.0.0") && ip_Int <= IpToInt("127.255.255.255"))
{
this.country = "本機(jī)內(nèi)部環(huán)回地址";
this.local = "";
nRet = 1;
}
else if ((ip_Int >= IpToInt("0.0.0.0") && ip_Int <= IpToInt("2.255.255.255")) || (ip_Int >= IpToInt("64.0.0.0") && ip_Int <= IpToInt("126.255.255.255")) || (ip_Int >= IpToInt("58.0.0.0") && ip_Int <= IpToInt("60.255.255.255")))
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注