import os
#填入企业微信web请求地址
webhook_url = 'https://qyapi.weixin.qq.com/cgi-bin'
# 发送消息的函数
def send_message(msg):
    headers = {'Content-Type': 'application/json'}
    data = {'msgtype': 'text', 'text': {'content': msg}}
    r = requests.post(webhook_url, headers=headers, data=json.dumps(data))
    return r.json()
#获取当前登录用户的连接IP地址
def get_local_user_ip():
    cmd = "who am i | awk '{print $NF}'"
    output = os.popen(cmd).read().strip()
    return output

user_ip = get_local_user_ip()

mes = f"IP {user_ip} 已登录服务器"
send_message(mes)