Disable IPv6
All checks were successful
Build and Publish ipserv / build_and_publish (push) Successful in 1m15s
All checks were successful
Build and Publish ipserv / build_and_publish (push) Successful in 1m15s
This commit is contained in:
parent
10df69722d
commit
bc13c0dcc2
1 changed files with 22 additions and 2 deletions
24
ipserv.py
24
ipserv.py
|
@ -4,6 +4,7 @@ import time
|
|||
import os
|
||||
import aiohttp
|
||||
import random
|
||||
import ipaddress
|
||||
from fastapi import FastAPI, Header, Request, Query, HTTPException
|
||||
from fastapi.responses import JSONResponse, PlainTextResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
@ -95,6 +96,13 @@ async def ip(
|
|||
else:
|
||||
ip = request.client.host
|
||||
|
||||
try:
|
||||
_ip = ip_address.ip_address(ip)
|
||||
if isinstance(_ip, ipaddress.IPv6Address):
|
||||
raise HTTPException(400, detail="IPv6 is not supported at this time.")
|
||||
except ValueError:
|
||||
raise HTTPException(400, detail="%r does not appear to be a valid IP address" % ip)
|
||||
|
||||
logging.info("looking up IP info for %s", ip)
|
||||
data = await make_request(
|
||||
ip,
|
||||
|
@ -120,6 +128,13 @@ async def lookup(ip: str = Query(...), User_Agent: str = Header("Mozilla/5.0")):
|
|||
return JSONResponse(data)
|
||||
logging.info("cache expired for %s", ip)
|
||||
|
||||
try:
|
||||
_ip = ip_address.ip_address(ip)
|
||||
if isinstance(_ip, ipaddress.IPv6Address):
|
||||
raise HTTPException(400, detail="IPv6 is not supported at this time.")
|
||||
except ValueError:
|
||||
raise HTTPException(400, detail="%r does not appear to be a valid IP address" % ip)
|
||||
|
||||
logging.info("looking up IP info for %s", ip)
|
||||
data = await make_request(
|
||||
ip,
|
||||
|
@ -139,8 +154,13 @@ async def lookup(ip: str = Query(...), User_Agent: str = Header("Mozilla/5.0")):
|
|||
@app.get("/imfeelinglucky")
|
||||
async def im_feeling_lucky(req: Request):
|
||||
host = req.client.host
|
||||
if host.count(".") != 3:
|
||||
raise HTTPException(400, "IPv4 only endpoint.")
|
||||
|
||||
try:
|
||||
_ip = ip_address.ip_address(host)
|
||||
if isinstance(_ip, ipaddress.IPv6Address):
|
||||
raise HTTPException(400, detail="IPv6 is not supported at this time.")
|
||||
except ValueError:
|
||||
raise HTTPException(400, detail="%r does not appear to be a valid IP address" % host)
|
||||
|
||||
data = await make_request(host, {"User-Agent": "Mozilla/5.0 Nex/19.04.2024"})
|
||||
if not isinstance(data, dict):
|
||||
|
|
Reference in a new issue