惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 司徒正美
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
Help Net Security
Help Net Security
N
News and Events Feed by Topic
O
OpenAI News
L
LangChain Blog
F
Full Disclosure
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
Cloudbric
Cloudbric
W
WeLiveSecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
罗磊的独立博客
Attack and Defense Labs
Attack and Defense Labs
PCI Perspectives
PCI Perspectives
TaoSecurity Blog
TaoSecurity Blog
AI
AI
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
T
Threatpost
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Last Week in AI
Last Week in AI
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 聂微东
P
Proofpoint News Feed
Latest news
Latest news
S
SegmentFault 最新的问题
J
Java Code Geeks
T
Threat Research - Cisco Blogs
H
Help Net Security
P
Privacy International News Feed

博客园 - Caviare

前台优化法则(YSlow) ASP.NET MVC源代码 启用IIS的Gzip压缩功能 web.sitemap Dynamic Generation SQL字符正则匹配 委托应用 WorkBook操作实例 迭代器和排序基本使用 Bertrand Meyer提出的设计模式的原则 - Caviare - 博客园 Web.cofig详解[转] UpdatePanel Control [转老赵博客] .Net环境下的缓存技术介绍 (转) [转]webservice和remoting在分布式程序中的应用 sql2005备份在sql2000中恢复 Excel WorkBook操作例 温故知新-Excel操作类 SQL collation设置 一张类的访问权限图,帮您加深概念 [转]您可能不知道的Asp.Net2.0技巧
判断大陆IPAddress
Caviare · 2007-11-05 · via 博客园 - Caviare

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace IPInfoService
{
    
public class AddressService
    
{
        
public List<IPArea> listIP = new List<IPArea>();

        
/// <summary>
        
/// 填充大陆IP代码段列表
        
/// </summary>

        public AddressService()
        
{
            
string iPDBPath = @"D:\ApexLog\eTrade\Clicks\ipDB\country-ipv4.lst";//Down loaded from "http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst"
            StreamReader srIp = new StreamReader(iPDBPath);
            
while (!srIp.EndOfStream)
            
{
                
string strLine = srIp.ReadLine();
                
int index = strLine.IndexOf("cn");
                
if (index != -1)
                
{
                    
string[] strArr = strLine.Split(' ');

                    listIP.Add(
new IPArea(strArr[0], strArr[2]));
                }

            }

            srIp.Close();
        }


        
/// <summary>
        
/// 该IP是否来自中国大陆
        
/// </summary>
        
/// <param name="ipAddress"></param>
        
/// <returns></returns>

        public bool ScopeIncludingIpAddress(string ipAddress)
        
{
            
long intCurrentIP = IpToInt(ipAddress);
            
for (int i = 0; i < listIP.Count; i++)
            
{
                
if (IpToInt(listIP[i].strIpStart) <= intCurrentIP && intCurrentIP <= IpToInt(listIP[i].strIpEnd))
                
{
                    
return true;
                }

            }

            
return false;
        }


        
/// <summary>
        
/// IP地址转换成Int数据
        
/// </summary>
        
/// <param name="ip"></param>
        
/// <returns></returns>

        private long IpToInt(string ip)
        
{
            
char[] dot = new char[] '.' };
            
string[] ipArr = ip.Split(dot);
            
if (ipArr.Length == 3)
                ip 
= ip + ".0";
            ipArr 
= ip.Split(dot);

            
long ip_Int = 0;
            
long p1 = long.Parse(ipArr[0]) * 256 * 256 * 256;
            
long p2 = long.Parse(ipArr[1]) * 256 * 256;
            
long p3 = long.Parse(ipArr[2]) * 256;
            
long p4 = long.Parse(ipArr[3]);
            ip_Int 
= p1 + p2 + p3 + p4;
            
return ip_Int;
        }


    }


    
public class IPArea
    
{
        
public string strIpStart;
        
public string strIpEnd;
        
public IPArea(string strStart,string strEnd)
        
{
            
this.strIpEnd = strEnd;
            
this.strIpStart = strStart;
        }

    }

}