python访问现金盘源码出售搭建的公网ip地址的代码

下面资料是关于python访问现金盘源码出售搭建q-1152880099的公网ip地址的内容,应该对小伙伴们有用途。

import urllib,random,re

ip_regex = re.compile("(([0-9]{1,3}.){3}[0-9]{1,3})")

def public_ip():
''' Returns your public IP address.
Output: The IP address in string format.
None if not internet connection available.
'''
# List of host which return the public IP address:
for i in range(3):
host = random.choice(hosts)
try:
results = ip_regex.findall(urllib.urlopen(host).read(200000))
if results: return results[0][0]
except:
pass # Let's try another host
return None
#!/usr/bin/python
import os
import re

def getFile(path):

fList = os.listdir(path) #将指定目录内的文件以列表格式输出
os.chdir(path)
docuPath = os.getcwd() #获取根路径
fileList = []
for f in fList: #对目录内的文件进行遍历
if os.path.isdir(f): #判断文件类型是否为目录
getFile(f) #若是目录,递归运行此函数,继续进行遍历。
else:
fl = os.path.join(docuPath,f) #若不是目录,则结合文件名和根路径获得文件的绝对路径
fileList.append(fl)
#print(fileList)
return fileList

def changeFile():
for j in getFile("/opt"): #这里调用上个函数输出的fileList列表
a = open(j,"r") #打开每个文件
b = a.read()
if re.findall("hello",b): #判断文件内容里是否含有“hello”
c = open(j,"w")
c.write("HELLO!\n") #若含有,将“hello”改为“HELLO”。
a.close()

changeFile()

猜你喜欢

转载自www.cnblogs.com/bozisuan/p/11236349.html
今日推荐