上传文件至 脚本
This commit is contained in:
parent
c5bbbd6405
commit
ae4a18e70a
|
@ -0,0 +1,42 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
# 读取文本文件
|
||||||
|
file_path = 'C:/Users/andin/Desktop/2.txt.txt'
|
||||||
|
output_base_path = r'C:/Users/andin/Desktop/zhuwenbao/1828151960117535477554_{}.json'
|
||||||
|
|
||||||
|
# 逐行读取文本文件
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
lines = file.readlines() # 一次性读取所有行
|
||||||
|
index = 0 # 用于生成不同的文件名
|
||||||
|
|
||||||
|
# 每五行为一组
|
||||||
|
for i in range(0, len(lines), 5):
|
||||||
|
group = []
|
||||||
|
for j in range(i, min(i + 5, len(lines))):
|
||||||
|
line = lines[j].strip()
|
||||||
|
parts = line.split()
|
||||||
|
if len(parts) >= 4:
|
||||||
|
ip_address = parts[0]
|
||||||
|
port = parts[1]
|
||||||
|
identifier = parts[2]
|
||||||
|
date_location = ' '.join(parts[3:])
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'ip_address': ip_address,
|
||||||
|
'port': int(port),
|
||||||
|
'identifier': identifier,
|
||||||
|
'date_location': date_location
|
||||||
|
}
|
||||||
|
group.append(data)
|
||||||
|
|
||||||
|
# 如果group中有数据,则生成新的文件名并写入JSON文件
|
||||||
|
if group:
|
||||||
|
# 生成新的文件名
|
||||||
|
output_json_path = output_base_path.format(index)
|
||||||
|
# 将当前组的数据写入 JSON 文件
|
||||||
|
with open(output_json_path, 'w', encoding='utf-8') as json_file:
|
||||||
|
json.dump(group, json_file, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
print(f"JSON 文件已成功生成: {output_json_path}")
|
||||||
|
index += 1
|
|
@ -0,0 +1,27 @@
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
|
def test_port(ip, port):
|
||||||
|
# 创建一个 socket 对象
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.settimeout(5) # 设置超时时间
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 尝试连接指定的 IP 和端口
|
||||||
|
result = sock.connect_ex((ip, int(port))) # 确保 port 是整数
|
||||||
|
if result == 0:
|
||||||
|
print(f"端口 {port} 在地址 {ip} 上是开放的")
|
||||||
|
else:
|
||||||
|
print(f"无法连接到 {ip}:{port}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"连接测试失败: {e}")
|
||||||
|
finally:
|
||||||
|
sock.close() # 关闭 socket 连接
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 测试端口,替换下面的 IP 和端口号为你想要测试的值
|
||||||
|
test_ip = "121.36.27.6"
|
||||||
|
target_port =80
|
||||||
|
# 这里的 target_port 是一个整数,表示要测试的端口号
|
||||||
|
test_port(test_ip, target_port) # 调用函数 test_port
|
|
@ -0,0 +1,31 @@
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
|
def test_port(ip, port):
|
||||||
|
# 创建一个 socket 对象
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.settimeout(5) # 设置超时时间
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 尝试连接指定的 IP 和端口
|
||||||
|
result = sock.connect_ex((ip, port))
|
||||||
|
if result == 0:
|
||||||
|
print(f"端口 {port} 在地址 {ip} 上是开放的")
|
||||||
|
else:
|
||||||
|
print(f"无法连接到 {ip}:{port}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"连接测试失败: {e}")
|
||||||
|
finally:
|
||||||
|
sock.close() # 关闭 socket 连接
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
filename = 'C:/Users/andin/Desktop/zhuwenbao.txt'
|
||||||
|
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
for line in file:
|
||||||
|
parts = line.strip().split()
|
||||||
|
if len(parts) >= 2:
|
||||||
|
ip = parts[0] # 第一部分是 IP 地址
|
||||||
|
port = int(parts[1]) # 第二部分是端口号
|
||||||
|
test_port(ip, port) # 调用函数 test_port
|
|
@ -0,0 +1,29 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
# 读取文本文件
|
||||||
|
file_path = 'C:/Users/andin/Desktop/wangsu.txt'
|
||||||
|
output_json_path = 'C:/Users/andin/Desktop/output.json'
|
||||||
|
|
||||||
|
# 初始化一个空列表来存储解析后的数据
|
||||||
|
data_list = []
|
||||||
|
|
||||||
|
# 逐行读取文本文件
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
parts = line.strip().split()
|
||||||
|
if len(parts) >= 3:
|
||||||
|
number = parts[0]
|
||||||
|
location_operator = parts[1]
|
||||||
|
province = parts[2]
|
||||||
|
data = {
|
||||||
|
'number': number,
|
||||||
|
'location_operator': location_operator,
|
||||||
|
'province': province
|
||||||
|
}
|
||||||
|
data_list.append(data)
|
||||||
|
|
||||||
|
# 将数据写入 JSON 文件
|
||||||
|
with open(output_json_path, 'w', encoding='utf-8') as json_file:
|
||||||
|
json.dump(data_list, json_file, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
print(f"JSON 文件已成功生成: {output_json_path}")
|
|
@ -0,0 +1,20 @@
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
# 确保这里的路径是正确的,并且文件确实存在于此路径下
|
||||||
|
file_path = r'C:\Users\andin\Desktop\zhuwenbao.xlsx'
|
||||||
|
|
||||||
|
# 设置 pandas 选项以显示所有行和列
|
||||||
|
pd.set_option('display.max_rows', None) # 显示所有行
|
||||||
|
pd.set_option('display.max_columns', None) # 显示所有列
|
||||||
|
|
||||||
|
# 使用 pandas 的 read_excel 函数读取文件
|
||||||
|
try:
|
||||||
|
data = pd.read_excel(file_path)
|
||||||
|
# 显示数据的全部内容
|
||||||
|
print(data)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"发生了一个错误: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue