脚本专栏 
首页 > 脚本专栏 > 浏览文章

获取外网IP并发送到指定的邮箱的脚本

(编辑:jimmy 日期: 2024/11/16 浏览:3 次 )
编译后的exe文件,方便大家直接使用 下载地址 https://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
上一篇:AutoIt脚本的反编译和代码格式化问题分析
下一篇:使用AutoIT实现自动登录/退出客户端软件,删除日志
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。