发现网卡变百兆自动发送邮件通知的AutoIt源码

问题的出现

网吧维护中,由于交换机或水晶机或工艺上的问题,有些机器网卡正常的千兆会变成百兆,在无盘系统中启动机器或启动游戏变得很慢,用户体验相当不好!出现这个问题时,网管或维护却很难第一时间发现1000M变成100M的问题机器。
以下是使用autoit3写的,发现任意网卡是100M,就会按mail.ini配置文件中指定的邮件发送邮件通知,让你第一时间发现这种网卡变100M的问题机器,及时进行处理!

把以下代码保存为au3脚本或编译为可执行文件后,需要在同目录下建一个mail.ini文件,内容如下
[setup]
FromAddress=发件人@qq.com
toaddress=收件人@qq.com
username=qq号
password=QQ的smtp服务器提供的邮件授权码
body=邮件正文内容

其中password内容,应该进入你的QQ邮箱开通smtp和取得授权码
qq邮箱授权码

使用方法

设置好mainl.ini中的qq的smtp服务器的用户名及授权码等一切信息后,开机执行一次此代码就行,检测完成自动退出程序

autoit源码如下

以下为autoit3实现发现任意一网卡是100M,自动根据设置的邮件发送邮件通知!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#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
ExitLoop
endif
Next

if $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 UDF
Func _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
;

成品下载地址

已编译为可执行文件下载

下载地址 密码:3xw7di

-------------本文已结束赏个小钱吧-------------
×

感谢您的支持,我们会一直保持!

扫码支持
请土豪扫码随意打赏

打开微信扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

64.7K