热门关键字:  ubuntu  分区  linux系统进程  函数  Fedora

当前位置 :| 主页>Linux教程>编程开发>Perl>

[perl]支持网段端口扫描

来源: 作者: 时间:2008-05-16 Tag: 点击:
最近一直在学习perl,越看越对Per喜爱。这几天刚好想扫描网段而不想下载端口扫描软件,于是网上找了相关资料后就用perl写一个端口扫描。

没什么技术可言,作个标记!

#!/usr/bin/perl -w

#Description: check is_host_alive and is_host_port_open

#Author: donghao

#Date: 2008-05-15


use strict;
use IO::Socket::INET;
use Net::Ping;

# Global Variable

my $Start_pt = $ARGV[1];
my $End_pt = $ARGV[2];
my @ip_net;

#ReadMe

sub Usage(){
print "Note:\n";
print "perl scan_port.pl Ipaddr_File Start_Port End_Port\n";
print "For example: perl scan_port.pl Filename 1 10000\n";
print "Note:The file contains single ip address(192.168.1.2)";
print " or ip network(192.168.1.1-192.168.1.254)\n";
print "Good Luck!\n"
}

#Is_ip_network_or_single_ip

sub Is_ip_nk{
if($_[0] =~ /(^\d+)\.(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.(\d+)\.(\d+$)/){
for(my $var=$4;$var<=$8;$var++){
&Is_ip_correct($1,$2,$3,$var);
push @ip_net,"$1\.$2\.$3\.$var";
}
return 1;
}
return 0;
}

#Is_Host_Alive or Dead

sub Is_Host_Alive{
my $tmp_syn=Net::Ping->new("syn");
$tmp_syn->ping($_[0]);
if(!$tmp_syn->ack){
printf "The Host %-15s was dead!\n",$_[0];
$tmp_syn->close;
return 0;
}
$tmp_syn->close;
return 1;
}
上一篇:perl中访问oracle10g入门
下一篇:没有了
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表