os.popen('route add default gw %s' % (self.default_gw)) def pptp_living(self): has_route = os.popen( '''route -n | awk -F " " '{printf $8}' | grep ppp''').read() if has_route: return True return False def change_ip(self): new_ip = '' while True: self.close_pptp() if self.link_pptp(): new_ip = self.get_ip() self.logger.info('change ip to %s', new_ip) return new_ip sleep(1) if __name__ == '__main__': dirname, filename = os.path.split(os.path.abspath(sys.argv[0])) log_file = dirname + '/logs/ip_manager.log' logInit(logging.DEBUG, log_file, 10, True) m = IPManager('hcpptp001.ros2.chengshu.com', 'hcpptp001', '98273452') t1 = time() ip = m.change_ip() t2 = time() print t2 - t1, ip
# -*- coding: utf-8 -* import os import sys sys.path.append('/tools/python_common') sys.path.append('..') import logging from account import PptpAccount from common_func import logInit if __name__ == '__main__': file_path = 'account.txt' if len(sys.argv) >= 2: file_path = sys.argv[1] logInit(logging.DEBUG, 'logs/account.log', 10, True) ac = PptpAccount('192.168.60.17:2181') ac.set_account_from_file(file_path, ' ')
response = requests.post(url, data = post_values, headers = post_headers, timeout = 5) logging.info('-----response_status_code is %d : -----' % response.status_code) resHtml = response.text except requests.exceptions.RequestException as e: counter += 1 logging.error('%s, counter = %d' % (str(e), counter)) else: # update_Mongodb(mongodbConn, curstart, '', 0) return resHtml if __name__ == '__main__': DIR_PATH = os.path.split(os.path.realpath(__file__))[0] LOG_FILE = DIR_PATH + '/logs/' + __file__.replace('.py', '.log') logInit(logging.INFO, LOG_FILE, 0, True) mongodbConn = pymongo.MongoClient('192.168.60.65', 10010) pages = getpage_Mongodb(mongodbConn) for page in pages: time.sleep(1) response = fetch_instruments(page) if not response: logging.error('fetch failed! failed page = %d' % (page)) update_Mongodb(mongodbConn, page, '', 0) else: response = response.encode('utf-8') #不加这一句抓取失败 keywords = r'(?<=\d\.).*(?= 国)' sites = re.findall(keywords, response) if 0 == len(sites): update_Mongodb(mongodbConn, page, '', 0)
} r = requests.get(URL_STR, proxies=proxies) if r.status_code == 200: #return r.text pdb.set_trace() sel = Selector(text = r.text) print sel.xpath('//div[@class="sw-mod-navigatebar fd-clr"]//li[@id="breadCrumbText"]/em/text()').extract() else: print r.status_code print proxies return '' if __name__ == '__main__': logInit(logging.INFO, 'logs/test_pptp_proxy.log', 0, True) ip = '10.10.10.23' port = '8899' username = '******' password = '******' if len(sys.argv) > 2: ip = sys.argv[1] port = sys.argv[2] if len(sys.argv) > 4: username = sys.argv[3] password = sys.argv[4] else: username = '' password = ''
except Exception, e: logging.warning(str(e)) continue def get_my_name(): f_name = os.getenv('FATHER_HOST_NAME') f_name = f_name if f_name else 'unknown_hostname' hostname = os.popen('hostname').read() return ':'.join([f_name, hostname.strip()]) if __name__ == '__main__': ## 0. init log dirname, filename = os.path.split(os.path.abspath(sys.argv[0])) log_file = dirname + '/logs/pptp_proxy.log' logInit(logging.INFO, log_file, 10, True) logging.info('start') ## 0. get name and proxy ip proxy_port = int(os.getenv('PROXY_PORT')) proxy_ip = os.getenv('PROXY_IP') proxy_tj_ip = os.getenv('PROXY_TJ_IP') name = get_my_name() if not proxy_ip and not proxy_tj_ip: logging.error('not find proxy ip! please run docker with "-e PROXY_IP=X.X.X.X"!') sys.exit(1) ## 1. connect mongo mongo_db = get_mongo_db() ## 2. get pptp account from zookeeper