[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转载代码] Perl脚本采集电脑信息

主要用于收集ip、mac、姓名、房间,后来又加入了维修记录的功能。服务器端接受数据并存入数据库中。
  1. use strict;
  2. use Tk;
  3. use Encode;
  4. #SOCKE参数
  5. my $PF_INET = 2;
  6. my $port = 2345;
  7. my $remote_addr = pack('SnC4x8',$PF_INET,$port,192,168,138,228);
  8. my $SOCK_DGRAM = 2;
  9. #Frame
  10. my ($label_room, $label_name, $label_ctrl, $label_notice);
  11. #确定、取消
  12. my ($enter, $cancel);
  13. #房间、姓名变量
  14. my ($room, $name);
  15. $room = '';
  16. $name = '';
  17. #主界面
  18. my $mw = MainWindow->new(-title => hanzi('信息收集'));
  19. $mw->minsize(qw/200 100/);
  20. $mw->maxsize(qw/200 100/);
  21. #三个Frame
  22. $label_room = $mw->Frame( qw/-borderwidth 2 -relief groove/ )->pack( qw/-side top -fill both/ );
  23. $label_name = $mw->Frame( qw/-borderwidth 2 -relief groove/ )->pack( qw/-side top -fill both/ );
  24. $label_ctrl = $mw->Frame( qw/-borderwidth 2 -relief groove/ )->pack( qw/-side top -fill both/ );
  25. #房间号码输入
  26. $label_room->Label(-text => hanzi('房间号码'))->pack(qw/-side left -expand 1/);
  27. $label_room->Entry(-textvariable => \$room, -relief => 'groove')->pack(qw/-side right -expand 1/);
  28. #姓名输入
  29. $label_name->Label(-text => hanzi('姓名'))->pack(qw/-side left -expand 1/);
  30. $label_name->Entry(-textvariable => \$name, -relief => 'groove')->pack(qw/-side right -expand 1/);
  31. #确定与重置
  32. $enter = $label_ctrl->Button(-text => hanzi('确定'), -command => \&enter)->pack(qw/-side left -expand 1/);
  33. $cancel = $label_ctrl->Button(-text => hanzi('重置'), -command => \&cancel)->pack(qw/-side right -expand 1/);
  34. #提示
  35. $label_notice = $mw->Label(-text => hanzi('欢迎使用'), -relief => 'groove', -background => '#FFFF99')->pack(qw/-side bottom -fill x/);
  36. MainLoop();
  37. #汉字解码
  38. sub hanzi{
  39. return decode('gb2312', shift);
  40. }
  41. #确定函数
  42. sub enter{
  43. chomp($room);
  44. chomp($name);
  45. $room =~ s/^\s+//;
  46. $name =~ s/^\s+//;
  47. if($room eq '' or $name eq ''){
  48. $label_notice->configure(-text => hanzi('输入不能为空')) ;
  49. return 0;
  50. }#if
  51. else{
  52. open(IPCF,'-|',"ipconfig -all");
  53. my ($mac_addr, $ip_addr, $out_buffer);
  54. while(<IPCF>){
  55. chomp;
  56. if($_ = ~s/(.*)(00(\-[0-9A-Z]{2}){5})(.*)/$2/){
  57. $mac_addr = join('', split(/-/,$_));
  58. }
  59. if($_ = ~/IP Address/){
  60. $_ = ~s/(.*)([0-9]{3}(\.[0-9]{1,3}){3})(.*)/$2/;
  61. $ip_addr = $_;
  62. }
  63. }#while
  64. $out_buffer = $room."\t".$mac_addr."\t".$ip_addr."\t".encode('utf8', $name);
  65. socket(UDP_CLIENT, $PF_INET, $SOCK_DGRAM, getprotobyname('udp'));
  66. send(UDP_CLIENT, $out_buffer, 0, $remote_addr);
  67. close(UDP_CLIENT);
  68. close(IPCF);
  69. $mw->destroy();
  70. }#else
  71. }
  72. #重置函数
  73. sub cancel{
  74. $label_notice->configure(-text => hanzi('重置为空'));
  75. $room = '';
  76. $name = '';
  77. }
复制代码

返回列表