看到有佬友说你的github用户名怎么这么短,我也想要看看有多短啊!!但是看不见,我不服,我现在就要测试测试还有没有哪些短用户名没有被注册
我马上就开始用Claude帮我写了几个函数来检测检测,咱们只需要接口就好了,剩下的,交给天意,如果你有代理加上代理,没有代理就不要请求太多次数,被封了就完蛋啦
import requests
import random
import string
import json
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor, as_completed
import threading
url = "https://github.com/signup_check/username?value="
proxyHost = ""
proxyPort = ""
proxyUser = ""
proxyPass = ""
proxies = {
"http": f"http://{proxyUser}:{proxyPass}@{proxyHost}:{proxyPort}",
"https": f"http://{proxyUser}:{proxyPass}@{proxyHost}:{proxyPort}",
}
def check_single_username(username, log_filename):
"""检查单个用户名的可用性"""
try:
response = requests.get(url + username, proxies=proxies)
is_available = "is available" in response.text
log_entry = {
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"username": username,
"available": is_available,
}
with open(log_filename, "a", encoding="utf-8") as f:
f.write(json.dumps(log_entry, ensure_ascii=False) + "\n")
if is_available:
print(f"发现可用用户名: {username}")
return username
except Exception as e:
error_entry = {
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"username": username,
"error": str(e),
}
with open(log_filename, "a", encoding="utf-8") as f:
f.write(json.dumps(error_entry, ensure_ascii=False) + "\n")
print(f"检查用户名 {username} 时发生错误: {str(e)}")
return None
def check_usernames(usernames, max_workers=10):
"""使用线程池并发检查用户名"""
available = []
log_filename = f"username_check_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
# 创建线程锁用于同步日志写入
log_lock = threading.Lock()
with ThreadPoolExecutor(max_workers=max_workers) as executor:
# 提交所有任务
future_to_username = {
executor.submit(check_single_username, username, log_filename): username
for username in usernames
}
# 获取结果
for future in as_completed(future_to_username):
result = future.result()
if result:
available.append(result)
return available
def generate_random_username():
length = random.randint(1, 5)
characters = string.ascii_lowercase + string.digits
username = "".join(random.choice(characters) for _ in range(length))
return username
def generate_meaningful_username():
# 超短的技术相关词汇(2-4字符)
tech_short = [
"py",
"js",
"go",
"ai",
"ml",
"db",
"ui",
"os",
"it",
"dev",
"app",
"api",
"bot",
"git",
"web",
]
# 短的形容词(3-5字符)
adj_short = [
"big",
"new",
"old",
"hot",
"top",
"red",
"max",
"pro",
"ace",
"key",
"raw",
"net",
"zen",
"neo",
"hex",
]
# 短的名词(3-5字符)
noun_short = [
"cat",
"fox",
"owl",
"bee",
"sun",
"sky",
"sea",
"ice",
"fire",
"wind",
"star",
"moon",
"rock",
"wave",
"lab",
]
# 短的动词(3-5字符)
verb_short = [
"run",
"fly",
"dig",
"mix",
"fix",
"make",
"code",
"hack",
"test",
"push",
"pull",
"build",
"ship",
"load",
]
# 单字母组合(极简风格)
letters = "abcdefghijklmnopqrstuvwxyz"
# 数字范围调整为更短
short_nums = list(range(1, 100)) # 1-99,避免过长数字
# 随机选择生成模式,增加更多短用户名模式
pattern = random.randint(1, 12)
if pattern == 1:
# 技术词 + 数字 (如: py42, js7)
username = random.choice(tech_short) + str(random.choice(short_nums))
elif pattern == 2:
# 单词 + 单字母 (如: cat-x, fox-z)
username = random.choice(noun_short) + random.choice(letters)
elif pattern == 3:
# 字母 + 技术词 (如: x-py, z-js)
username = random.choice(letters) + random.choice(tech_short)
elif pattern == 4:
# 超短组合:形容词+名词 (如: bigcat, hotfix)
username = random.choice(adj_short) + random.choice(noun_short)
elif pattern == 5:
# 技术词组合 (如: pybot, jsapp)
username = random.choice(tech_short) + random.choice(tech_short)
elif pattern == 6:
# 动词+名词 (如: runbot, fixbug)
username = random.choice(verb_short) + random.choice(noun_short)
elif pattern == 7:
# 单字母+数字 (如: x99, z42)
username = random.choice(letters) + str(random.choice(short_nums))
elif pattern == 8:
# 技术词+字母 (如: pyx, goz)
username = random.choice(tech_short) + random.choice(letters)
elif pattern == 9:
# 双字母+数字 (如: xy7, ab3)
username = (
random.choice(letters)
+ random.choice(letters)
+ str(random.choice(range(1, 10)))
)
elif pattern == 10:
# 名词+动词 (如: catrun, foxfly)
username = random.choice(noun_short) + random.choice(verb_short)
elif pattern == 11:
# 纯技术词 (如: py, js, go)
username = random.choice(tech_short)
else:
# 形容词+技术词 (如: newpy, hotjs)
username = random.choice(adj_short) + random.choice(tech_short)
return username
def generate_ultra_short_username():
"""生成1-4字符的超短用户名"""
patterns = [
# 1字符
lambda: random.choice("abcdefghijklmnopqrstuvwxyz"),
# 2字符:字母+数字
lambda: random.choice("abcdefghijklmnopqrstuvwxyz") + str(random.randint(1, 9)),
# 2字符:双字母
lambda: "".join(random.choices("abcdefghijklmnopqrstuvwxyz", k=2)),
# 3字符:技术词
lambda: random.choice(["py", "js", "go", "ai", "ml", "ui", "os", "it"])
+ random.choice("xyz"),
# 4字符:短词
lambda: random.choice(
["code", "hack", "dev", "app", "web", "bot", "api", "git"]
),
]
return random.choice(patterns)()
def generate_batch_usernames(count=100, prefer_short=True):
"""批量生成用户名,可选择偏向短用户名"""
usernames = []
for _ in range(count):
if prefer_short and random.random() < 0.7: # 70%概率生成超短用户名
username = generate_ultra_short_username()
else:
username = generate_meaningful_username()
# 确保用户名符合GitHub规范且不重复
if len(username) <= 39 and username not in usernames:
usernames.append(username)
return usernames
if __name__ == "__main__":
print("开始生成短用户名...")
# 生成偏向短用户名的批次
usernames = generate_batch_usernames(1000, prefer_short=True)
# 显示生成的用户名样本
print(f"生成了 {len(usernames)} 个用户名,前20个示例:")
for i, username in enumerate(usernames[:20], 1):
print(f"{i:2d}. {username} ({len(username)}字符)")
print(f"\n开始检查可用性...")
# 使用10个线程并发检查
available = check_usernames(usernames, max_workers=10)
if available:
# 按长度排序
available.sort(key=len)
# 保存结果到文件
result_filename = f"available_usernames_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
with open(result_filename, "w", encoding="utf-8") as f:
f.write(f"找到 {len(available)} 个可用用户名:\n")
f.write("-" * 50 + "\n")
for username in available:
f.write(f"✓ {username} ({len(username)}字符)\n")
print(f"\n找到 {len(available)} 个可用用户名:")
print(f"结果已保存到文件: {result_filename}")
# 显示前20个最短的用户名
print("\n最短的20个可用用户名:")
for i, username in enumerate(available[:20], 1):
print(f"{i:2d}. {username} ({len(username)}字符)")
else:
print("\n没有找到可用的用户名,建议重新运行或调整生成策略")