Computer Information collection program written in Perl

Source: Internet
Author: User

CopyCode The Code is as follows: it is mainly used to collect IP addresses, MAC addresses, names, and rooms, and later added the service record function. The server accepts the data and stores it in the database.
#############################
Use strict;
Use TK;
Use encode;

# Socke Parameters
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 );

# Confirm and cancel
My ($ enter, $ cancel );

# Room and name variables
My ($ room, $ name );
$ Room = '';
$ Name = '';

# Main Interface
My $ Mw = mainwindow-> New (-Title => Hanzi ('Collect information '));
$ MW-> minsize (QW/200 100 /);
$ MW-> maxsize (QW/200 100 /);

# Three Frames
$ 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 /);

# Enter the room number
$ Label_room-> label (-TEXT => Hanzi ('room number')-> pack (QW/-side left-expand 1 /);
$ Label_room-> entry (-textvariable = >\$ room,-relief => 'groove')-> pack (QW/-side right-expand 1 /);

# Name input
$ Label_name-> label (-TEXT => Hanzi ('name')-> pack (QW/-side left-expand 1 /);
$ Label_name-> entry (-textvariable = >\$ name,-relief => 'groove')-> pack (QW/-side right-expand 1 /);

# Confirm and reset
$ Enter = $ label_ctrl-> button (-TEXT => Hanzi ('OK'),-command => \ & enter) -> pack (QW/-side left-expand 1 /);
$ Cancel = $ label_ctrl-> button (-TEXT => Hanzi ('reset '),-command => \ & cancel) -> pack (QW/-side right-expand 1 /);

# Prompt
$ Label_notice = $ MW-> label (-TEXT => Hanzi ('Welcome use'),-relief => 'groove',-background => '# ffff99 ') -> pack (QW/-side bottom-fill x /);

Mainloop ();

# Chinese character decoding
Sub Hanzi {
Return decode ('gb2312', shift );
}

# Determining a function
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 blank '));
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
}

# Resetting Functions
Sub cancel {
$ Label_notice-> Configure (-TEXT => Hanzi ('reset to null '));
$ Room = '';
$ Name = '';
}

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.