Commit 8331235f authored by Łukasz Nowak's avatar Łukasz Nowak

recurlests: Provide shorthand IP option

Still allow advanced resolve_all, but for 99% of cases providing IP is enough.
parent 5bffc86c
......@@ -7,10 +7,11 @@ from . import recurlests
@click.option('--output/--no-output', help="Shows the output", default=False, show_default=True)
@click.option('--curl', help="Path to curl binary", default='curl', show_default=True)
@click.option('--follow/--no-follow', help="Follows redirects", default=False, show_default=True)
@click.option('--ip', help="IP to resolve to")
@click.argument("url")
def runRecurl(headers, output, curl, follow, url):
def runRecurl(headers, output, curl, follow, ip, url):
mimikra = recurlests.Recurlests(curl)
response = mimikra.get(url, allow_redirects=follow)
response = mimikra.get(url, ip=ip, allow_redirects=follow)
print('Effective HTTP version:', response.effective_http_version)
print('Response status code:', response.status_code)
print('Response status:', response.ok and "ok" or "error")
......
import json
import urllib.parse
import tempfile
import subprocess
from requests.structures import CaseInsensitiveDict
......@@ -43,6 +44,7 @@ class Recurlests(object):
url,
http3=True,
http3_only=False,
ip=None,
resolve_all=None,
verify=True,
allow_redirects=True,
......@@ -90,9 +92,14 @@ class Recurlests(object):
command_list.extend(['--header', '@%s' % (request_header_file,)])
if auth is not None:
command_list.extend(['--user', '%s:%s' % auth])
if ip is not None:
if resolve_all is None:
resolve_all = {}
parsed = urllib.parse.urlparse(url)
port = parsed.port or 443 if parsed.scheme == 'https' else 80
if resolve_all is not None:
for port, ip in resolve_all.items():
command_list.extend(['--resolve', '*:%s:%s' % (port, ip)])
for port, ip_ in resolve_all.items():
command_list.extend(['--resolve', '*:%s:%s' % (port, ip_)])
if http3_only:
command_list.append('--http3-only')
if timeout is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment