码迷,mamicode.com
首页 > 其他好文 > 详细

gai ip

时间:2020-07-29 17:54:47      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:aac   his   basic   sts   read   deb   http   cut   while   

# coding=utf-8
# This script is uesd to modify Agent IP at the first time of machine started.

import requests
import json
import time
import os
import logging

def main():
    logging.basicConfig(level=logging.INFO, filename="C:\\iplogs.txt", filemode="a", format="[%(asctime)s] - %(levelname)s: %(message)s")
    ip = ""

    while not ip:
        try:
            logging.info("Requesting http://192.168.56.1:1338/sandbox_ip?key=b4a2e173a29da1de12b8418ce96d5739")
            response = requests.get("http://192.168.56.1:1338/sandbox_ip?key=b4a2e173a29da1de12b8418ce96d5739")
            logging.info("HTTP status code: {}".format(response.status_code))
            if response.text:
                ip = json.loads(response.text)["data"]
                logging.debug("Get ip: 192.168.56.{}".format(ip)) 
        except Exception as e:
            logging.error("Timeout")
            time.sleep(5)
    logging.info("Modify IP to 192.168.56.{}".format(ip))
    modifyresult = os.popen("netsh interface ip set address \"±¾µØÁ¬½Ó\" static 192.168.56.{} 255.255.255.0 192.168.56.1".format(ip)).read()
    logging.info(modifyresult)
    os.remove("C:\\Users\\Agent\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\modifyip.py")

if __name__ == __main__:
    main()

 

gai ip

标签:aac   his   basic   sts   read   deb   http   cut   while   

原文地址:https://www.cnblogs.com/zhoujunhao/p/13397919.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!