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 ...@@ -7,10 +7,11 @@ from . import recurlests
@click.option('--output/--no-output', help="Shows the output", default=False, show_default=True) @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('--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('--follow/--no-follow', help="Follows redirects", default=False, show_default=True)
@click.option('--ip', help="IP to resolve to")
@click.argument("url") @click.argument("url")
def runRecurl(headers, output, curl, follow, url): def runRecurl(headers, output, curl, follow, ip, url):
mimikra = recurlests.Recurlests(curl) 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('Effective HTTP version:', response.effective_http_version)
print('Response status code:', response.status_code) print('Response status code:', response.status_code)
print('Response status:', response.ok and "ok" or "error") print('Response status:', response.ok and "ok" or "error")
......
import json import json
import urllib.parse
import tempfile import tempfile
import subprocess import subprocess
from requests.structures import CaseInsensitiveDict from requests.structures import CaseInsensitiveDict
...@@ -43,6 +44,7 @@ class Recurlests(object): ...@@ -43,6 +44,7 @@ class Recurlests(object):
url, url,
http3=True, http3=True,
http3_only=False, http3_only=False,
ip=None,
resolve_all=None, resolve_all=None,
verify=True, verify=True,
allow_redirects=True, allow_redirects=True,
...@@ -90,9 +92,14 @@ class Recurlests(object): ...@@ -90,9 +92,14 @@ class Recurlests(object):
command_list.extend(['--header', '@%s' % (request_header_file,)]) command_list.extend(['--header', '@%s' % (request_header_file,)])
if auth is not None: if auth is not None:
command_list.extend(['--user', '%s:%s' % auth]) 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: if resolve_all is not None:
for port, ip in resolve_all.items(): for port, ip_ in resolve_all.items():
command_list.extend(['--resolve', '*:%s:%s' % (port, ip)]) command_list.extend(['--resolve', '*:%s:%s' % (port, ip_)])
if http3_only: if http3_only:
command_list.append('--http3-only') command_list.append('--http3-only')
if timeout is None: 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