gyn

Win32下的Perl,无用的select,停滞的Tk,结束吧....

单位电脑信息采集程序

r_gui.JPG
主要用于收集ip、mac、姓名、房间,后来又加入了维修记录的功能。服务器端接受数据并存入数据库中。
#############################
use strict;
use Tk;
use Encode;

#SOCKE参数
my $PF_INET = 2;
my $port = 2345;
my $remote_addr = pack('SnC4x8',$PF_INET,$port,192,168,138,228);
my $SOCK_DGRAM = 2;

#Frame
my ($label_room, $label_name, $label_ctrl, $label_notice);

#确定、取消
my ($enter, $cancel);

#房间、姓名变量
my ($room, $name);
$room = '';
$name = '';

#主界面
my $mw = MainWindow->new(-title => hanzi('信息收集'));
$mw->minsize(qw/200 100/);
$mw->maxsize(qw/200 100/);

#三个Frame
$label_room = $mw->Frame( qw/-borderwidth 2 -relief groove/ )->pack( qw/-side top -fill both/ );
$label_name = $mw->Frame( qw/-borderwidth 2 -relief groove/ )->pack( qw/-side top -fill both/ );
$label_ctrl = $mw->Frame( qw/-borderwidth 2 -relief groove/ )->pack( qw/-side top -fill both/ );

#房间号码输入
$label_room->Label(-text => hanzi('房间号码'))->pack(qw/-side left -expand 1/);
$label_room->Entry(-textvariable => \$room, -relief => 'groove')->pack(qw/-side right -expand 1/);

#姓名输入
$label_name->Label(-text => hanzi('姓名'))->pack(qw/-side left -expand 1/);
$label_name->Entry(-textvariable => \$name, -relief => 'groove')->pack(qw/-side right -expand 1/);

#确定与重置
$enter = $label_ctrl->Button(-text => hanzi('确定'), -command => \&enter)->pack(qw/-side left -expand 1/);
$cancel = $label_ctrl->Button(-text => hanzi('重置'), -command => \&cancel)->pack(qw/-side right -expand 1/);

#提示
$label_notice = $mw->Label(-text => hanzi('欢迎使用'), -relief => 'groove', -background => '#FFFF99')->pack(qw/-side bottom -fill x/);

MainLoop();

#汉字解码
sub hanzi{
    return decode('gb2312', shift);   
}

#确定函数
sub    enter{
    chomp($room);
    chomp($name);
    $room =~ s/^\s+//;
    $name =~ s/^\s+//;
    if($room eq '' or $name eq ''){
        $label_notice->configure(-text => hanzi('输入不能为空')) ;
        return 0;
    }#if
    else{
        open(IPCF,'-|',"ipconfig -all");
       
        my ($mac_addr, $ip_addr, $out_buffer);
        while(<IPCF>){
            chomp;
            if($_ = ~s/(.*)(00(\-[0-9A-Z]{2}){5})(.*)/$2/){
                $mac_addr = join('', split(/-/,$_));
            }
            if($_ = ~/IP Address/){
                $_ = ~s/(.*)([0-9]{3}(\.[0-9]{1,3}){3})(.*)/$2/;
                $ip_addr = $_;
            }
        }#while
        $out_buffer = $room."\t".$mac_addr."\t".$ip_addr."\t".encode('utf8', $name);
       
        socket(UDP_CLIENT, $PF_INET, $SOCK_DGRAM, getprotobyname('udp'));
        send(UDP_CLIENT, $out_buffer, 0, $remote_addr);
       
        close(UDP_CLIENT);
        close(IPCF);
        $mw->destroy();
    }#else       
}

#重置函数
sub cancel{
    $label_notice->configure(-text => hanzi('重置为空'));
    $room = '';
    $name = '';
}

posted on 2006-10-20 19:03 gyn_tadao 阅读(479) 评论(3)  编辑 收藏 引用 所属分类: perl

评论

# re: 单位电脑信息采集程序 2006-10-26 17:10 戴尔网站

有价值,谢谢  回复  更多评论   

# re: 单位电脑信息采集程序 2006-10-28 22:08 才子£鸣

什么语言??怪怪的.  回复  更多评论   

# re: 单位电脑信息采集程序 2006-10-29 08:38 gyn_tadao

perl,后来我又改过了增加了一些交互和数据库检测的功能。  回复  更多评论   

只有注册用户登录后才能发表评论。
<2006年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(15)

随笔分类(126)

随笔档案(108)

相册

搜索

最新评论

阅读排行榜

评论排行榜