Improve host IP address handling in HttpCli

Added logic to detect if the user provided an IP address or hostname using the ipaddress module. This ensures correct resolution and mapping behavior based on the input type, improving reliability and correctness in network operations.
This commit is contained in:
Masked 2025-07-27 15:30:56 -04:00 committed by ed
parent ca6d0b8d5e
commit e2c2dd18cf

View file

@ -4875,11 +4875,22 @@ class HttpCli(object):
ep = self.host
host = ep.split(":")[0]
hport = ep[ep.find(":") :] if ":" in ep else ""
rip = (
host
if self.args.rclone_mdns or not self.args.zm
else self.conn.hsrv.nm.map(self.ip) or host
)
import ipaddress
try:
ipaddress.ip_address(host)
user_used_ip = True
except ValueError:
user_used_ip = False
if user_used_ip or self.args.rclone_mdns or not self.args.zm:
rip = (
host
if self.args.rclone_mdns or not self.args.zm
else self.conn.hsrv.nm.map(self.ip) or host
)
else:
rip = host
# safer than html_escape/quotep since this avoids both XSS and shell-stuff
pw = re.sub(r"[<>&$?`\"']", "_", self.pw or "hunter2")
vp = re.sub(r"[<>&$?`\"']", "_", self.uparam["hc"] or "").lstrip("/")