吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6995|回复: 64
收起左侧

[原创工具] 【小工具】端口访问邮件提醒,可用于RDP和Radmin远程登录通知

  [复制链接]
1073 发表于 2023-2-17 20:10
本帖最后由 1073 于 2023-2-20 17:30 编辑

工具介绍:


    主要实现的功能是获取指定端口连接的远程 IP 地址,并将其发送给指定的邮箱,可用于一些远程工具的登录通知,或者其他你需要检测的程序。
   
特点:
1.  可在配置文件内自定义需要检测的端口;支持多端口检测
2.  白名单功能,可设置多个IP排除;
3.  使用zmail模块发送邮件更高效方便,不需要手动添加服务器地址、端口以及适合的协议,zmail会帮你完成;


2023/2/20日更新:

有朋友希望能检测多个端口,便做了一下修改支持多端口。


下载地址在楼下
>>>传送门<<<
--------------------------------------------------------------------------------

多端口提示效果:
邮件效果.jpg

配置文件:

INI配置说明.jpg




-------------------------------以下为原帖---------------------------------

邮件提示效果:
演示效果.png




RDP登录设置演示:




Radmin登录设置演示:


设置配置:
INI配置说明.jpg



单个端口版本下载地址:https://1073.lanzouo.com/iyFe40nvuhah   提取码2023


文件信息:
文件信息.png



python源码:
[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
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
import psutil
import getpass
import time
import zmail
import configparser
import socket
 
 
def get_remote_ips(port, wl_list):
    remote_ips = [conn.raddr[0] for conn in psutil.net_connections()
                  if conn.raddr and conn.status == 'ESTABLISHED'
                  and not conn.raddr[0].startswith('127.')
                  and ':' not in conn.raddr[0]
                  and conn.laddr[1] == port
                  ]
    remote_ips = list(set(remote_ips))
 
    if not remote_ips or any(ip.startswith(wl) for ip in remote_ips for wl in wl_list if wl):
        return []
    return remote_ips
 
 
def send_mail(remote_ips, config):
    aa1, aa2 = socket.gethostname(), getpass.getuser()
    aa3 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
 
    ip_list = [ip + '\n' for ip in remote_ips]
    content = (
            '<font size="4">检测时间: {}<br>'.format(aa3)
            + '主机名: {}<br>'.format(aa1)
            + '用户名: {}<br>'.format(aa2)
            + '连接端口 "{}" 的IP地址:<br></font>'.format(port)
            + '<b><font color="#ff0000" size="5">{}</font></b><br>'.format('<br>'.join(ip_list))
            + '<a >查询IP归属地</a>'.format('<br>'.join(ip_list))
    )
 
    from_addr, pwd = config.get('Mail', 'from_addr'), config.get('Mail', 'pwd')
    title = config.get('Mail', 'title')
    to_addr = config.get('to_addr', 'add').split(',')
    server = zmail.server(from_addr, pwd)
    server.send_mail(to_addr, {'subject': title, 'content_html': content})
 
 
config = configparser.ConfigParser()
config.read('Mail.ini', encoding="utf-8-sig")
wl_list = config.get('WL', 'add').split(',')
port = int(config.get("port", "net_port"))
 
remote_ips = get_remote_ips(port, wl_list)
if remote_ips:
    send_mail(remote_ips, config)

免费评分

参与人数 9吾爱币 +16 热心值 +9 收起 理由
mayi1001 + 1 + 1 谢谢@Thanks!
hysxm666 + 1 + 1 我很赞同!
萧然独奏 + 2 + 1 热心回复!
Redragon + 1 + 1 谢谢@Thanks!
抱薪风雪雾 + 1 + 1 谢谢@Thanks!
tyz1234 + 1 + 1 谢谢@Thanks!
pwdobwq + 1 + 1 分享者有动手能力编写工具解决工作上的实用工具
turinggu + 1 + 1 我很赞同!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 1073 发表于 2024-1-3 01:15

1、当远程登陆2008server系统时,看了一下计划任务是在运行的,而且一直在运行未 ...[/quote]

哦哦这个,因为我用的3.10以上的python版本,改天用个低版本重新编译下
 楼主| 1073 发表于 2023-2-21 02:10
GMCN 发表于 2023-2-21 00:02
楼主方便讲一下原理?

1.读取配置文件 'Mail.ini' 中的配置信息,包括白名单和检测端口
2.根据读取的端口信息,调用 get_remote_ips 函数获取指定端口的远程IP地址列表,并将其存储在 remote_ips_dict 字典中
3.根据 remote_ips_dict 字典中的数据生成邮件正文
4.使用 zmail 库发送邮件给指定的收件人地址,邮件包括检测时间、主机名、用户名、检测到的连接端口以及该端口连接的远程IP地址列表,同时提供查询IP归属地的链接。
一只大菜猫 发表于 2023-2-17 22:28
不过,感谢公布源码,我改成了微信推送,好用
 楼主| 1073 发表于 2023-2-17 22:30
一只大菜猫 发表于 2023-2-17 22:28
不过,感谢公布源码,我改成了微信推送,好用

哈哈,分享下代码,我也学习下
cq2002 发表于 2023-2-17 22:39
多谢分享。这个确实方便很多
heiye 发表于 2023-2-17 23:12
多谢分享。这个确实方便很多
Redragon 发表于 2023-2-17 23:54
非常不错,如果有微信的代码就好了
 楼主| 1073 发表于 2023-2-18 00:49
Redragon 发表于 2023-2-17 23:54
非常不错,如果有微信的代码就好了

OK,这两天研究下
judgecx 发表于 2023-2-18 05:59
能多端口吗?
judgecx 发表于 2023-2-18 05:59
一只大菜猫 发表于 2023-2-17 22:28
不过,感谢公布源码,我改成了微信推送,好用

公众号吗?还是那个server酱
turinggu 发表于 2023-2-18 06:04
感谢分享源码,学习一波
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-2-13 18:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表