发新话题
打印

[原创]PERL的模块介绍和应用

[原创]PERL的模块介绍和应用

=========
[EST]  [CGI]
=========
转载请注明出处


NO.1
Sys::Hostname - Try every conceivable way to get hostname

例子:
复制内容到剪贴板
代码:
  use Sys::Hostname;
   $host = hostname;
   print "Hostname is:$host";
NO.2
Net::POP3 - Post Office Protocol 3 Client class (RFC1939)

例子:
复制内容到剪贴板
代码:
use Socket;
use Net::POP3;
print "Plesase Input POP3 Host:";
$host=<STDIN>;
print "waiting……";
$file1="FTPUSER";
$file2="FTPPASS";
open(FILE,"$file1")||die "$file1 not found\n";
while(@user=<FILE>){
foreach $user(@user){
chop($user);
open(FILE,"$file2")||die "$file2 not found\n";
while(@password=<FILE>){
foreach $password(@password){
chop($password);
$pop = Net::POP3->new($HOST,Timeout =>60)||die "bad!\n";
if($pop){
$a=$POP->login($User,$Password);
$pop->quit;
if ($a==1){
print "congratulations! user:$user  password:$password\n";
exit;
}
}
  }
  }
}  
}
NO.3
Win32::GetOSVersion()

例子:
复制内容到剪贴板
代码:
use Win32;
$a=Win32::GetOSVersion();
if($a==0) print "Win32s";
if($a==1) print "Win32s or Windows95 or Windows98 or Windows Me";
if($a==2) print "Windows NT 3.51 or Windows NT 4 or Windows 2000 or Windows XP or windows .NET Server ";
exit ;
返回的ID值给$a

   OS              ID   MAJOR  MINOR
   Win32s            0    -     -
   Windows 95         1    4     0
   Windows 98         1    4    10
   Windows Me         1    4    90
   Windows NT 3.51      2    3    51
   Windows NT 4        2    4     0
   Windows 2000        2    5     0
   Windows XP         2    5     1
   Windows .NET Server   2    5     1

这样就可以简单的实现系统判断。

NO.4
Win32::GetOSName()

例子:
复制内容到剪贴板
代码:
use Win32;
$osname=Win32::GetOSVersion();
print "$osname";
直接输出操作系统版本。


NO.5
Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])

例子:
复制内容到剪贴板
代码:
use Win32;
$message="黑客基地\nwww.hackbase.com\n";
$flags=4;
$title="消息";
$a=Win32::MsgBox($message , $flags , $title);
[flags]
      0 = OK
      1 = OK and Cancel
      2 = Abort, Retry, and Ignore
      3 = Yes, No and Cancel
      4 = Yes and No
      5 = Retry and Cancel      
      MB_ICONSTOP       "X" in a red circle
      MB_ICONQUESTION    question mark in a bubble
      MB_ICONEXCLAMATION  exclamation mark in a yellow triangle
      MB_ICONINFORMATION  "i" in a bubble

弹出对话框,返回操作值给$a,根据$a的值我们可以进行判断,然后进入下一个步骤。


NO.6
Win32::NodeName() -- Returns the Microsoft Network node-name of the current machine.

例子:
复制内容到剪贴板
代码:
use Win32;
$a=Win32::NodeName();
print "$a";
NO.7
Win32::LoginName()--Returns the username of the owner of the current perl process.

例子:
复制内容到剪贴板
代码:
use Win32;
$a=Win32::LoginName();
print "$a";
NO.8
use Win32API::File 0.08 qw( :ALL );

例子:
复制内容到剪贴板
代码:
use Win32API::File 0.08 qw( :ALL );
@roots= getLogicalDrives();
print "@roots";
输出本地机器上的所有的磁盘


NO.9
DeleteFile( $sFileName )

例子:
复制内容到剪贴板
代码:
use Win32API::File 0.08 qw( :ALL );
$s=<STDIN>;
chop($s);
$a=DeleteFile( $s );
if($a==1) print "删除文件成功!";
http://hi.baidu.com/fengze

TOP

NO.10

注册表操作:
use Win32API::Registry 0.21 qw( :ALL );

RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\Disk", 0, KEY_READ, $key );
   or  die "Can&#39;t open HKEY_LOCAL_MACHINE\\SYSTEM\\Disk: ",
        regLastError(),"\n";        #打开注册表

  RegQueryValueEx( $key, "Information", [], $type, $data, [] );
   or  die "Can&#39;t read HKEY_L*MACHINE\\SYSTEM\\Disk\\Information: ",
        regLastError(),"\n";

  [上面是读取注册表的信息,也可以在上面对注册表进行操作,可以参考perl的帮助文档...]

  RegCloseKey( $key )
   or  die "Can&#39;t close HKEY_LOCAL_MACHINE\\SYSTEM\\Disk: ",
        regLastError(),"\n";
                            #关闭注册表
http://hi.baidu.com/fengze

TOP

发新话题