问题的出现网吧维护中,由于交换机或水晶机或工艺上的问题,有些机器网卡正常的千兆会变成百兆,在无盘系统中启动机器或启动游戏变得很慢,用户体验相当不好!出现这个问题时,网管或维护却很难第一时间发现1000M变成100M的问题机器。以下是使用autoit3写的,发现任意网卡是100M,就会按mail.ini配置文件中指定的邮件发送邮件通知,让你第一时间发现这种网卡变100M的问题机器,及时进行处理! 把以下代码保存为au3脚本或编译为可执行文件后,需要在同目录下建一个mail.ini文件,内容如下[setup]FromAddress=发件人@qq.comtoaddress=收件人@qq.comusername=qq号password=QQ的smtp服务器提供的邮件授权码body=邮件正文内容 其中password内容,应该进入你的QQ邮箱开通smtp和取得授权码 使用方法设置好mainl.ini中的qq的smtp服务器的用户名及授权码等一切信息后,开机执行一次此代码就行,检测完成自动退出程序 autoit源码如下以下为autoit3实现发现任意一网卡是100M,自动根据设置的邮件发送邮件通知! 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Include<file.au3>#NoTrayIcon$badlan=false$a = _GetAdaptersInfo() For $i = 1 To $a[0][0] $lSpeed=GetIfEntry($a[$i][3])if $lSpeed=100 then $badlan=true ExitLoopendifNextif $badlan=true then $SmtpServer = "smtp.qq.com" ; address for the smtp-server to use - REQUIRED $FromName = "发送人" ; name from who the email was sent $FromAddress = IniRead(@WorkingDir&"\mail.ini","setup","FromAddress","") $ToAddress = IniRead(@WorkingDir&"\mail.ini","setup","toaddress","") $Subject = @ComputerName&"号机器网卡为100M,请检查!" ; subject from the email - can be anything you want it to be ;$Body = "邮件正文" ; the messagebody from the mail - can be left blank but then you get a blank mail $Body = IniRead(@WorkingDir&"\mail.ini","setup","body","") $AttachFiles = "" ; the file you want to attach- leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = IniRead(@WorkingDir&"\mail.ini","setup","Username","") $Password = IniRead(@WorkingDir&"\mail.ini","setup","Password","") $IPPort = 465 ; port used for sending the mail $ssl = 1 $rc = _INetSmtpMailCom ( $SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl )endif;msgbox(0,"",$ToAddress)Func SetListView() $a = _GetAdaptersInfo() $index = ($a[1][3]) For $i = 1 To $a[0][0] GUICtrlCreateListViewItem($a[$i][1] & '|' & _ StringLeft(Hex($a[$i][2]), 12) & '|' & _ $a[$i][6] & '|' & _ GetIfEntry($a[$i][3]) & ' MB', $ListView1) Next EndFunc ;==>SetListView Func GetIfEntry($ifIndex) Local $tagBuffer, $tBuffer, $pBuffer, $iResult, $iSpeed, $sDescr $tagBuffer = "wchar[256];dword[5];byte[8];dword[16];char[256]" $tBuffer = DllStructCreate($tagBuffer) $pBuffer = DllStructGetPtr($tBuffer) DllStructSetData($tBuffer, 2, $ifIndex, 1) $iResult = DllCall("iphlpapi.dll", "long", "GetIfEntry", "ptr", $pBuffer) $iSpeed = DllStructGetData($tBuffer, 2, 4) / 1000 / 1000 $sDescr = DllStructGetData($tBuffer, 5) $tBuffer = 0 Return SetError($iResult[0], $iSpeed, $iSpeed) EndFunc ;==>GetIfEntry Func _GetAdaptersInfo() Local $iResult, $tBuffer, $pBuffer, $aResult[1][9], $tagADPTINFO, $tAdpt ; 第一次调用传递空值,pOutBufLen ( $iResult[2] ) 设为结构所需大小,单位byte。 $iResult = DllCall("iphlpapi.dll", "dword", "GetAdaptersInfo", "ptr", 0, "ulong*", 0) $tBuffer = DllStructCreate("byte[" & $iResult[2] & "]") ; 定义$iResult[2] 字节的缓存区域 (分配内存空间)。 $pBuffer = DllStructGetPtr($tBuffer) ; 获取内存指针。 ; 第二次调用,GetAdaptersInfo把网卡信息复制到指定的内存空间 ($tBuffer) 中。 $iResult = DllCall("iphlpapi.dll", "dword", "GetAdaptersInfo", "ptr", $pBuffer, "ulong*", $iResult[2]) ; $iResult[0]值为0则调用成功,否则为系统错误号。 ; 数据转换, byte --> IP_ADAPTER_INFO $tagADPTINFO = "ptr NextAdpt; dword ComboIndex; char AdptName[260]; char AdptDescr[132];uint AddrLength;byte MacAddr[8];dword Index;uint Type; uint DhcpEnabled;ptr CurrentIpAddr;ptr NextIpAddr; char IpAddr[16];char IpAddrMask[16]; dword IpAddrCxt; ptr NextGateway; char GatewayAddr[16]; char GatewayAddrMask[16];dword GatewayCxt; ptr NextDhcp; char DhcpAddr[16]; char DhcpAddrMask[16];dword DhcpCxt; int HaveWins; ptr NextPriWinsServer; char PriWinsServerAddr[16]; char PriWinsServerAddrMask[16]; dword PriWinsServerCxt; ptr NextSecWinsServer; char SecWinsServerAddr[16]; char SecWinsServerAddrMask[16]; dword LeaseObtained; dword LeaseExpires" While $pBuffer $tAdpt = DllStructCreate($tagADPTINFO, $pBuffer) $aResult[0][0] += 1 ReDim $aResult[$aResult[0][0] + 1][9] $aResult[$aResult[0][0]][0] = DllStructGetData($tAdpt, "AdptName") ; 网卡名称 $aResult[$aResult[0][0]][1] = DllStructGetData($tAdpt, "AdptDescr") ; 网卡描述 $aResult[$aResult[0][0]][2] = DllStructGetData($tAdpt, "MacAddr") ; 网卡MAC $aResult[$aResult[0][0]][3] = DllStructGetData($tAdpt, "Index") ; 网卡索引号 $aResult[$aResult[0][0]][4] = DllStructGetData($tAdpt, "Type") ; 类型 $aResult[$aResult[0][0]][5] = DllStructGetData($tAdpt, "DhcpEnabled") ; DHCP是否启用 true = 启用, false = 禁用 $aResult[$aResult[0][0]][6] = DllStructGetData($tAdpt, "IpAddr") ; IP 地址 $aResult[$aResult[0][0]][7] = DllStructGetData($tAdpt, "GatewayAddr") ; 网关地址 $aResult[$aResult[0][0]][8] = DllStructGetData($tAdpt, "DhcpAddr") ; DHCP地址, 只有DhcpEnabled为true时,此值才有效。 $pBuffer = DllStructGetData($tAdpt, "NextAdpt") ; [下一张网卡信息的内存地址。] $tAdpt = 0 WEnd $tBuffer = 0 Return SetError($iResult[0], 0, $aResult) EndFunc ;==>_GetAdaptersInfo; The UDFFunc _INetSmtpMailCom ( $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance= "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0 ) Local $objEmail = ObjCreate ( "CDO.Message" ) $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr ( $as_Body, "<" ) And StringInStr ( $as_Body, ">" ) Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit ( $s_AttachFiles, ";" ) For $x = 1 To $S_Files2Attach [ 0 ] $S_Files2Attach [ $x ] = _PathFull ( $S_Files2Attach [ $x ] ) ConsoleWrite ( '@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF ) ;### Debug Console If FileExists ( $S_Files2Attach [ $x ] ) Then $objEmail.AddAttachment ( $S_Files2Attach [ $x ] ) Else ConsoleWrite ( '!> File not found to attach: ' & $S_Files2Attach [ $x ] & @LF ) SetError ( 1 ) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2 $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = $s_SmtpServer If Number ( $IPPort ) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 1 $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) = $s_Username $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = $s_Password EndIf If $ssl Then $objEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = True EndIf ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ( "urn:schemas:mailheader:Importance" ) = "High" Case "Normal" $objEmail.Fields.Item ( "urn:schemas:mailheader:Importance" ) = "Normal" Case "Low" $objEmail.Fields.Item ( "urn:schemas:mailheader:Importance" ) = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError ( 2 ) Return $oMyRet [ 1 ] EndIf $objEmail= ""EndFunc ;==>_INetSmtpMailCom; 成品下载地址