用perl寫的單位電腦資訊採集程式

來源:互聯網
上載者:User

複製代碼 代碼如下:主要用於收集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 = '';
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.