擷取外網IP並發送到指定的郵箱的指令碼

來源:互聯網
上載者:User

指令碼之家編譯後的exe檔案,方便大家直接使用 http://www.jb51.net/softs/44627.html

設定檔內容如下: 複製代碼 代碼如下:設定檔代碼
[收件者]
收件地址=
郵件標題=
[發送人]
郵箱=
密碼=

核心代碼: 複製代碼 代碼如下:#region AutoIt3Wrapper 先行編譯參數(常用參數)
#AutoIt3Wrapper_Icon=D:\ico\3444\2222.ico ;表徵圖,支援EXE,DLL,ICO
#AutoIt3Wrapper_OutFile=GetIp_Sendmail.exe ;輸出檔案名
#AutoIt3Wrapper_OutFile_Type=exe ;檔案類型
#AutoIt3Wrapper_Compression=4 ;壓縮等級
#AutoIt3Wrapper_UseUpx=y ;使用壓縮
#AutoIt3Wrapper_Res_Comment= ;注釋
#AutoIt3Wrapper_Res_Description= ;詳細資料
#AutoIt3Wrapper_Res_Fileversion= ;檔案版本
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p ;自動更新版本
#AutoIt3Wrapper_Res_LegalCopyright= ;著作權
#AutoIt3Wrapper_Change2CUI=N ;修改輸出的程式為CUI(控制台程式)
;#AutoItAutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% ;自訂資源段
;#AutoIt3Wrapper_Run_Tidy= ;指令碼整理
;#AutoIt3Wrapper_Run_Obfuscator= ;代碼迷惑
;#AutoIt3Wrapper_Run_AU3Check= ;語法檢查
;#AutoIt3Wrapper_Run_Before= ;運行前
;#AutoIt3Wrapper_Run_After= ;運行後
#endregion AutoIt3Wrapper 先行編譯參數(常用參數)
#include <file.au3>
#include <Inet.au3>
#include <Date.au3>
;禁止重複運行。
$g_szVersion = '擷取外網IP並發送到指定郵箱'
If WinExists($g_szVersion) Then
Exit
EndIf
AutoItWinSetTitle($g_szVersion)

;托盤事件
Opt("TrayOnEventMode", 1);托盤事件通知
Opt("TrayMenuMode", 1) ; 預設功能表項目 (指令碼暫停中/退出)(Script Paused/Exit) 將不會顯示.
TrayCreateItem("發送")
TrayItemSetOnEvent(-1,'_Sendmail')
$exititem = TrayCreateItem("退出程式")
TrayItemSetOnEvent($exititem, "_Exit")
TraySetClick(16) ; 只有單擊第二個滑鼠按鍵(預設右鍵)才會顯示托盤菜單
TraySetToolTip('擷取外網IP並發送到指定郵箱')
TraySetState()

Global $testIp
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$s_ToAddress = IniRead(@ScriptDir & "\Config.ini", '收件者', '收件地址', '-1');收件者地址
$s_Subject = IniRead(@ScriptDir & "\Config.ini", '收件者', '郵件標題', '-1');郵件標題
TrayTip("準備就緒", "收件者地址:" & $s_ToAddress _
& @CRLF & "郵件標題:" & $s_Subject, 5, 1)

_Sendmail();發送郵件

AdlibRegister('_ReduceMemory', 1000 * 10);10秒整理一次記憶體

AdlibRegister('_Sendmail',1000*15)

While 1
Sleep(3000)
WEnd

Func _Exit()
Exit
EndFunc ;==>_Exit

;發送郵件====================================================================
Func _Sendmail()
$s_SmtpServer = "smtp.163.com" ;SMTP伺服器
$s_FromName = "bbs.wglm.net" ;郵件發送人
$s_FromAddress = IniRead(@ScriptDir & "\Config.ini", '發送人', '郵箱', '-1') ;郵件寄件者地址
$s_ToAddress = IniRead(@ScriptDir & "\Config.ini", '收件者', '收件地址', '-1');"19377708@qq.com" ;收件者地址
$s_Subject = IniRead(@ScriptDir & "\Config.ini", '收件者', '郵件標題', '-1');"AU3郵件發送測試" ;郵件標題
Do
$Getip = _GetIP();外網IP
Sleep(300)
TrayTip("提示", '正在擷取外網IP', 5, 1)
Until $Getip <> -1

If $testIp = $Getip Then
TrayTip("提示", '外網IP與上次發送的相同' & @CRLF & '程式將不重複發送.', 5, 1)
Return ;MsgBox(0,'',$Getip)
EndIf
$testIp = $Getip
$as_Body = "外網IP:" & $Getip & @CRLF & "發送時間:" & _NowDate() & " " & _NowTime() ;郵件內文;擷取外網IP
$s_AttachFiles = "" ;附件地址
$s_CcAddress = "" ;抄送地址
$s_BccAddress = "" ;密件副本地址
$s_Username = IniRead(@ScriptDir & "\Config.ini", '發送人', '郵箱', '-1') ;使用者名稱
$s_Password = IniRead(@ScriptDir & "\Config.ini", '發送人', '密碼', '-1') ;密碼
$IPPort = 25 ;傳送埠,Gmail使用的傳送埠為465
$ssl = 0
$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then
_FileWriteLog(@ScriptDir & "\MailSendlog.log", "郵件發送失敗 錯誤碼:" & @error & " 描述:" & $rc)
TrayTip("郵件發送失敗", "錯誤碼:" & @error _
& @CRLF & "描述:" & $rc, 5, 1)
Else
_FileWriteLog(@ScriptDir & "\MailSendlog.log", "郵件發送成功 收件者地址: " & $s_ToAddress & " 郵件標題: " & $s_Subject & " 郵件內文:" & $as_Body)
TrayTip("郵件發送成功", "收件者地址: " & $s_ToAddress _
& @CRLF & "郵件標題: " & $s_Subject _
& @CRLF & "郵件內文:" & $as_Body, 5, 1)
EndIf

EndFunc ;==>_Sendmail

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
$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])
If FileExists($S_Files2Attach[$x]) Then
$objEmail.AddAttachment($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x]
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
$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
; Sent the Message
$objEmail.Send
If @error Then
SetError(2)
Return $oMyRet[1]
EndIf
EndFunc ;==>_INetSmtpMailCom
; Com Error Handler
Func MyErrFunc()
$HexHexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
;發送郵件結束====================================================================

;整理記憶體
Func _ReduceMemory()
$I_PID = @AutoItPID
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $I_PID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.