Unit Computer Information Acquisition program in Perl-application techniques

Source: Internet
Author: User
Tags pack

Copy Code code as follows:

Mainly used to collect IP, Mac, name, room, and then added the maintenance record function. The server side accepts the data and stores it in the database.
#############################
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);

#确定, cancellation
My ($enter, $cancel);

#房间, name variables
My ($room, $name);
$room = ';
$name = ';

#主界面
My $MW = mainwindow->new (-title => Hanzi (' Information gathering '));
$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);
$label _name = $MW->frame (qw/-borderwidth 2-relief groove/)->pack (Qw/-side Top-fill);
$label _ctrl = $MW->frame (qw/-borderwidth 2-relief groove/)->pack (Qw/-side Top-fill);

#房间号码输入
$label _room->label (-text => hanzi (' room number ')->pack (Qw/-side Left-expand);
$label _room->entry (-textvariable => \ $room,-relief => ' Groove ')->pack (Qw/-side Right-expand);

#姓名输入
$label _name->label (-text => hanzi (' name '))->pack (Qw/-side Left-expand);
$label _name->entry (-textvariable => \ $name,-relief => ' Groove ')->pack (Qw/-side Right-expand);

#确定与重置
$enter = $label _ctrl->button (-text => hanzi (' OK '),-command => \&enter)->pack (Qw/-side Left-expand);
$cancel = $label _ctrl->button (-text => hanzi (' Reset '),-command => \&cancel)->pack (qw/-side Right-expand 1 /);

#提示
$label _notice = $MW->label (-text => Hanzi (' Welcome to use '),-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 (' Input cannot be empty '));
return 0;
} #if
else{
Open (ipcf, '-| ', "Ipconfig-all");

My ($mac _addr, $ip _addr, $out _buffer);
while (<IPCF>) {
Chomp
if ($_ = ~s/(. *) (\-[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 (' Reset to null '));
$room = ';
$name = ';
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.