免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2691 | 回复: 7
打印 上一主题 下一主题

如何用 perl 检查一个 IP 是否在某个 IP 段里? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-02 23:09 |只看该作者 |倒序浏览
我现在有一个 IP 段列表,现在需要实现检查某一个 IP 是否在这个 IP 段里面,不知道用 PERL 如何实现?

招聘 : Java研发
论坛徽章:
0
2 [报告]
发表于 2007-11-02 23:23 |只看该作者
原帖由 chuan 于 2007-11-2 23:09 发表
我现在有一个 IP 段列表,现在需要实现检查某一个 IP 是否在这个 IP 段里面,不知道用 PERL 如何实现?


try check this module on cpan:
http://search.cpan.org/~marcel/N ... lib/Net/IP/Match.pm

论坛徽章:
0
3 [报告]
发表于 2007-11-02 23:27 |只看该作者
举个例子? 列表是文件?

招聘 : Java研发
论坛徽章:
0
4 [报告]
发表于 2007-11-02 23:28 |只看该作者
原帖由 chuan 于 2007-11-2 23:09 发表
我现在有一个 IP 段列表,现在需要实现检查某一个 IP 是否在这个 IP 段里面,不知道用 PERL 如何实现?


Also I once did the same thing as you, rather than using an existing module, you can convert the ip to int at first, then do the number comparsion to find what you want.

see the module source of mime:
http://search.cpan.org/~pangj/IP-ChinaISP-0.03/lib/IP/ChinaISP.pm

论坛徽章:
0
5 [报告]
发表于 2007-11-02 23:51 |只看该作者

回复 #4 pangj 的帖子

thanks to pangj..

I used perl and Net:NS module to setup a dynamic dns, that will reponse the backend server's ip which near the client.

which ip database that ChinaISP module used ?

招聘 : Java研发
论坛徽章:
0
6 [报告]
发表于 2007-11-03 00:03 |只看该作者
I used perl and Net::DNS module to setup a dynamic dns, that will reponse the backend server's ip which near the client.


Do you mean you wrote a DNS server based on Net::DNS module?
There's already a DNS Server Framework on internet:
http://www.stanford.edu/~riepel/lbnamed/Stanford-DNSserver/
It's much easy to use it to make a dns server.

which ip database that ChinaISP module used ?


got the IPs from apnic.

论坛徽章:
0
7 [报告]
发表于 2007-11-03 00:16 |只看该作者
it's simple code to setup a dns server based on Net::DNS::Nameserver.  :)

my $ns = Net::DNS::Nameserver -> new(
        LocalAddr    => [ '127.0.0.1' ],
        LocalPort    => 53,
        ReplyHandler => \&reply_handler,
        Verbose      => 0,
) || die "couldn't create nameserver object\n";

$ns->main_loop;


example code copy from Net::DNS::Nameserver module documentation.

I know Stanford-DNSserver, but never tested. do you thing it's better than Net::DNS::Nameserver? In the pass, I just use this dns for internal query by squid to point to the right backend.

now, I want to make the dns smart. :)

招聘 : Java研发
论坛徽章:
0
8 [报告]
发表于 2007-11-03 10:00 |只看该作者
Yup, I once used also Squid and smart DNS based on Stanford::DNS framework.
I didn't use Net::DNS::Server module, wish you good luck with it.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP