如果电脑IP每次开机后总是变动,那么接下来对你可能有帮助,话不多说上代码
import socket,requests
if __name__ == '__main__':
'''
开机获取本IP
'''
try:
hostname=socket.gethostname()
addrs = socket.getaddrinfo(hostname,None)
ips = []
ips.append(f'[{hostname}] IP 通知:')
for item in addrs:
ips.append(item[4][0])
robot_text ={
"msgtype": "text",
"text": { "content": "" },
"at": { "isAtAll": False }
}
robot_text['text']['content'] = '\n'.join(ips)
robot_url = 'https://oapi.dingtalk.com/robot/send?access_token=XXX