blob: b51065c0afc3093495946bf65948cd6b74910548 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/usr/bin/env python3
import asyncio
import httpx
import sys
async def check_url(client, url):
url = url.strip()
if not url:
return
if not url.startswith(('http://', 'https://')):
url = 'https://' + url
try:
response = await client.head(url, timeout=5.0, follow_redirects=True)
if response.status_code == 200:
print(f"[OK] {response.status_code} - {url}")
else:
print(f"[FAIL] {response.status_code} - {url}")
except Exception as e:
print(f"[ERROR] {type(e).__name__} - {url}")
async def main():
urls = sys.stdin.readlines()
if not urls:
print("No url provided.")
return
async with httpx.AsyncClient() as client:
tasks = [check_url(client, url) for url in urls]
await asyncio.gather(*tasks)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
|