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

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog
D
DataBreaches.Net
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
The Hacker News
The Hacker News
Latest news
Latest news
博客园_首页
T
Tenable Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
Spread Privacy
Spread Privacy
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
P
Privacy & Cybersecurity Law Blog
C
Cisco Blogs
I
InfoQ
The Cloudflare Blog
J
Java Code Geeks
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
P
Proofpoint News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
AWS News Blog
AWS News Blog
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
G
Google Developers Blog
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
Project Zero
Project Zero
P
Privacy International News Feed
Engineering at Meta
Engineering at Meta
G
GRAHAM CLULEY
博客园 - Franky
C
CERT Recently Published Vulnerability Notes

博客园 - 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;
        }

    }

}