65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
|
|
import pymysql
|
|||
|
|
import random
|
|||
|
|
|
|||
|
|
conn = pymysql.connect(host='10.8.0.252', user='root', password='Hbhyg731024@', database='pms')
|
|||
|
|
cur = conn.cursor()
|
|||
|
|
|
|||
|
|
# ICCID规则:
|
|||
|
|
# 中国移动:898600、898602、898604、898607
|
|||
|
|
# 中国联通:898601
|
|||
|
|
# 中国电信:898603
|
|||
|
|
|
|||
|
|
# 获取所有柜子
|
|||
|
|
cur.execute("SELECT id FROM cabinets ORDER BY id")
|
|||
|
|
cabinet_ids = [row[0] for row in cur.fetchall()]
|
|||
|
|
|
|||
|
|
# 运营商前缀
|
|||
|
|
carriers = [
|
|||
|
|
("898600", "移动"), # 中国移动
|
|||
|
|
("898601", "联通"), # 中国联通
|
|||
|
|
("898603", "电信"), # 中国电信
|
|||
|
|
("898602", "移动"), # 中国移动
|
|||
|
|
("898604", "移动"), # 中国移动
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
carrier_count = {"移动": 0, "联通": 0, "电信": 0}
|
|||
|
|
|
|||
|
|
for i, cab_id in enumerate(cabinet_ids):
|
|||
|
|
# 随机选择运营商
|
|||
|
|
prefix, carrier = random.choice(carriers)
|
|||
|
|
# 生成ICCID: 20位数字
|
|||
|
|
# 前6位(运营商) + 2位(年份) + 2位(省份) + 8位(流水) + 1位(校验)
|
|||
|
|
year = random.randint(20, 25)
|
|||
|
|
province = random.randint(10, 31)
|
|||
|
|
serial = random.randint(10000000, 99999999)
|
|||
|
|
check = random.randint(0, 9)
|
|||
|
|
iccid = f"{prefix}{year:02d}{province:02d}{serial:08d}{check}"
|
|||
|
|
|
|||
|
|
cur.execute(f"UPDATE cabinets SET iccid='{iccid}' WHERE id={cab_id}")
|
|||
|
|
carrier_count[carrier] += 1
|
|||
|
|
|
|||
|
|
conn.commit()
|
|||
|
|
|
|||
|
|
print("✓ ICCID更新完成")
|
|||
|
|
print(f"\n运营商分布:")
|
|||
|
|
for carrier, count in carrier_count.items():
|
|||
|
|
print(f" {carrier}: {count}个")
|
|||
|
|
|
|||
|
|
# 验证
|
|||
|
|
cur.execute("SELECT name, iccid FROM cabinets LIMIT 5")
|
|||
|
|
print(f"\n示例数据:")
|
|||
|
|
for row in cur.fetchall():
|
|||
|
|
iccid = row[1]
|
|||
|
|
prefix = iccid[:6] if iccid else ""
|
|||
|
|
if prefix.startswith("898600") or prefix.startswith("898602") or prefix.startswith("898604"):
|
|||
|
|
carrier = "移动"
|
|||
|
|
elif prefix.startswith("898601"):
|
|||
|
|
carrier = "联通"
|
|||
|
|
elif prefix.startswith("898603"):
|
|||
|
|
carrier = "电信"
|
|||
|
|
else:
|
|||
|
|
carrier = "未知"
|
|||
|
|
print(f" {row[0]}: {iccid} ({carrier})")
|
|||
|
|
|
|||
|
|
conn.close()
|