import os
import json
import socket
from socket import *
files = os.listdir("G:\\textFF")
print(files)
content = None
sucess = 0
badly = 0
for filedata in files:
#print(type(filedata))
fo = open("G:\\textFF"+"\\"+filedata,'rb')
#print(fo)
fr = fo.readline().decode('utf-8')
data = json.loads(fr)
#print(fr)
#print(type(data),data)
#print("IP和端口号:",data["addresses"][0],"服务器名称:",data["name"])
ffip = data["addresses"][0]["ip"]
ffport = data["addresses"][0]["port"]
#print("服务器名称:",data["name"],' ',"IP:",ffip,"端口号:",ffport)
s = socket(AF_INET,SOCK_STREAM)
addr = (ffip,ffport)
try:
s.connect(addr)
sucess += 1
print("连接成功第%d个 服务器名称:"%sucess, data["name"], ' ', "IP:", ffip, "端口号:", ffport)
except:
badly += 1
print("连接失败第%d个 服务器名称:"%badly, data["name"], ' ', "IP:", ffip, "端口号:", ffport)
print("共成功%d个 失败%d个"%(sucess,badly))
首先要在G盘创建textFF文件夹,文件夹下放txt文件,格式{“addresses”:[{“ip”:“xx.xx.x.xx”,“port”:xxxx}],“borntime”:0,“group”:“E”,“index”:15,“info”:“xx服”,“name”:“xx服”,“serverid”:xxxxx,“status”:“HOT”,“zoneid”:xxx,“zonename”:“xxxxx”}
可视情况自行更改,不保证完全准确