Skip to content

Commit

Permalink
asnblock: Switch WHOIS api to whois-dev.toolforge.org
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiCompositeNumber committed Aug 17, 2021
1 parent 81a252d commit 361724d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/asnblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0


# Copyright 2020 AntiCompositeNumber
# Copyright 2021 AntiCompositeNumber

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,7 +49,7 @@
cast,
)

__version__ = "1.2"
__version__ = "1.3"

logging.config.dictConfig(
utils.logger_config("ASNBlock", level="VERBOSE", filename="stderr")
Expand All @@ -60,6 +60,7 @@
simulate = False
session = requests.session()
session.headers.update({"User-Agent": toolforge.set_user_agent("anticompositebot")})
whois_api = "https://whois-dev.toolforge.org/gateway.py"

IPNetwork = Union[ipaddress.IPv4Network, ipaddress.IPv6Network]

Expand Down Expand Up @@ -237,14 +238,13 @@ def search_whois(net: IPNetwork, search_list: Iterable[str]) -> bool:
Search terms must be lowercase.
"""
logger.debug(f"Searching WHOIS for {search_list} in {net}")
url = "https://whois.toolforge.org/gateway.py"
params = {
"ip": str(net[0]),
"lookup": "true",
"format": "json",
}
try:
req = session.get(url, params=params)
req = session.get(whois_api, params=params)
req.raise_for_status()
for whois_net in req.json()["nets"]:
for search in search_list:
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_asnblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0


# Copyright 2020 AntiCompositeNumber
# Copyright 2021 AntiCompositeNumber

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_icloud_data(live_config):
)
@pytest.mark.parametrize("search", ["wikimedia", "foundation"])
@pytest.mark.skipif(
session.head("https://whois.toolforge.org/gateway.py").status_code == 503,
session.head(asnblock.whois_api).status_code == 503,
reason="Toolforge whois is down",
)
def test_search_whois(net, expected, search):
Expand Down

0 comments on commit 361724d

Please sign in to comment.