IP:port ပရောက်စီစာရင်းကို Python ဖြင့်ရှင်းလင်းခြင်း
ရိုးရိုး IPv4 ဖိုင်ကိုစစ်၍ port များပုံစံညှိကာ IP တူတွင် port မတူသည်ကိုထားပြီး ထပ်နေသည်ကိုဖယ်ပါ။
IPv4 IP:port တစ်ခုစီကို proxies.txt တွင် တစ်ကြောင်းစီထည့်ပါ။ အားလုံးသည် သိထားသောပရောက်စီ protocol တစ်မျိုးတည်းဖြစ်ရမည်။ အခမဲ့ပရောက်စီစာရင်းမှစုလျှင် ဤစာသား input မပြုလုပ်မီ protocol ခွဲပါ။ ရှင်းလင်းမှုသည် အကောင့်အချက်အလက်ပါ URL၊ CSV ကော်လံနှင့် IPv6 လိပ်စာကို လက်မခံပါ။
စံ library သုံးဤ script ကို တူညီသော directory တွင် clean-proxies.py ဟုသိမ်းပါ။
from ipaddress import IPv4Address
from pathlib import Path
seen = set()
cleaned = []
for number, raw in enumerate(
Path("proxies.txt").read_text(encoding="utf-8").splitlines(),
start=1,
):
text = raw.strip()
if not text:
continue
try:
host, port_text = text.rsplit(":", 1)
host = str(IPv4Address(host))
port = int(port_text)
if not 1 <= port <= 65535:
raise ValueError("port out of range")
except ValueError:
print(f"Skipping line {number}: invalid IPv4 endpoint")
continue
endpoint = (host, port)
if endpoint not in seen:
seen.add(endpoint)
cleaned.append(f"{host}:{port}")
output = "\n".join(cleaned)
Path("proxies-clean.txt").write_text(
output + ("\n" if output else ""),
encoding="utf-8",
)
print(f"Saved {len(cleaned)} endpoints")
ထို directory မှမောင်းပါ။
uv run --no-project python clean-proxies.py
ကျော်သည့်လိုင်းသတိပေးချက်နှင့် proxies-clean.txt ကိုကြည့်ပါ။ input ဖိုင်မပြောင်းပါ။ output သည် ပထမတွေ့အစဉ်ကိုထားပြီး လိပ်စာနှင့် ကိန်းဂဏန်း port အတွဲအလိုက် ထပ်နေသည်ကိုဖယ်သည်။ 203.0.113.10:8080 နှစ်ခုနှင့် 203.0.113.10:3128 တစ်ခုက endpoint နှစ်ခုဖြစ်သည်။ ဒဿမ port 08080 ကို 8080 သို့ညှိသည်။
စာတမ်းလိပ်စာများက ပုံစံကိုသာပြသည်။ မှန်ကန်သော IPv4 syntax တွင် ပုဂ္ဂလိကနှင့် အထူးသုံးလိပ်စာများလည်း ပါသဖြင့် ရှင်းထားသောစာရင်းတစ်ခု အများသုံးရောက်နိုင်မည်ဟု မဆိုလိုပါ။ အများသုံးသက်သက်စာရင်းအတွက် လိပ်စာမူဝါဒအတိအလင်းထည့်ပါ။
HTTP/SOCKS ရော input တွင် protocol ကို သီးခြားဖိုင် သို့မဟုတ် ကော်လံတွင်ထားပြီး port 1080 မှမခန့်မှန်းပါနှင့်။ တကယ့်ပုံစံက လေးထောင့်ကွင်းပါ IPv6 ဖြစ်လျှင် သင့်လျော်သော parser သုံးပါ။ script သည် ခန့်မှန်းမည့်အစား မထောက်ပံ့ input ကိုပယ်ပြီး output သည် ရရှိနိုင်မှု၊ အမည်ဝှက်မှု၊ နိုင်ငံ သို့မဟုတ် မြန်နှုန်းကိုမဖော်ပြပါ။ ၎င်းတို့အတွက် ထိန်းချုပ်ထားသည့် ချိတ်ဆက်မှုစမ်းသပ်ချက် လိုသည်။