当前位置:七道奇文章资讯编程技术Delphi编程
日期:2011-08-14 00:31:00  来源:本站整理

<b>perl版NC(Netcat)源码</b>[Delphi编程]

赞助商链接



  本文“<b>perl版NC(Netcat)源码</b>[Delphi编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

#!/usr/bin/perl

use strict;
use IO::Socket;
use IO::Select;
use Getopt::Std;

my%option;
getopts('lp:', %option);

# listen on local port
if(defined$option{'l'})
{
if( !defined$option{'p'})
{
&Usage();
exit(-1);
}

my$port = $option{'p'};
my$listen = IO::Socket::INET->new(Proto => 'tcp',
LocalPort => $port,
Listen => 1,
Reuse => 1)ordie"Listen on port $port error: $!n";

while(my$client_sock = $listen->accept())
{
&ProcessData($client_sock);
}
}

# if has no -l argument, maybe want to connect to other host
if(@ARGV != 2)
{
&Usage();
exit(-1);
}

my$client_sock = IO::Socket::INET->new(Proto => 'tcp', PeerHost => $ARGV[0], PeerPort => $ARGV[1]) || die"Connect to $ARGV[0]:$ARGV[1] error:$!n";
&ProcessData($client_sock);

sub ProcessData
{
my$client_sock = shift;

my$select = IO::Select->new();

$select->add( *STDIN);
$select->add($client_sock);

my$buffer;
while(1)
{
if( ! $select->exists($client_sock))
{
print"waiting connection....n";
last;
}

my@ready = $select->can_read;

formy$tmp_sock(@ready)
{
if($tmp_sock eq *STDIN)
{
if(my$recv_len = sysread( *STDIN, $buffer, 1024) )
{
if( ! syswrite($client_sock, $buffer))
{
$select->remove($client_sock);
$select->remove( *STDIN);
close($client_sock);

last;
}
}
else
{
$select->remove($client_sock);
$select->remove( *STDIN);
close($client_sock);

last;
}
}

elsif($tmp_sock eq $client_sock)
{
if(my$recv_len = sysread($client_sock, $buffer, 1024*5))
{
if( ! syswrite( *STDOUT, $buffer))
{
$select->remove($client_sock);
$select->remove( *STDIN);
close($client_sock);

last;
}
}
else
{
print"socket disconnected.n";
$select->remove($client_sock);
$select->remove( *STDIN);
close($client_sock);

last;
}
}
}
}
}

sub Usage
{
print"simple nc.pl, code by wustyunshu@hotmail.comn";
print"this script don't support -e cmd.exe, ^_^n";
print"Usage:n";
print"t -l -p 99n";
print"t 192.168.0.1 80n";
}


  以上是“<b>perl版NC(Netcat)源码</b>[Delphi编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • <b>hosts是什么 hosts文件在什么位置 若何改正hosts</b>
  • <b>在 Windows 8 中手动安装语言包</b>
  • <b>五个常见 PHP数据库问题</b>
  • Windows中Alt键的12个高效快速的利用本领介绍
  • <b>MySQL ORDER BY 的实现解析</b>
  • <b>详解MySQL存储历程参数有三种范例(in、out、inout)</b>
  • <b>Win8系统恢复出来经典的开始菜单的办法</b>
  • <b>Win8系统花屏怎么办 Win8系统花屏的办理办法</b>
  • <b>Windows 7系统下无线网卡安装</b>
  • <b>为什么 Linux不需求碎片整理</b>
  • <b>Windows 8中删除账户的几种办法(图)</b>
  • <b>教你如安在win7下配置路由器</b>
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .