proxyverge-utils 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proxyverge_utils-1.0.0/LICENSE +21 -0
- proxyverge_utils-1.0.0/PKG-INFO +84 -0
- proxyverge_utils-1.0.0/README.md +59 -0
- proxyverge_utils-1.0.0/pyproject.toml +39 -0
- proxyverge_utils-1.0.0/setup.cfg +4 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils/__init__.py +5 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils/checker.py +27 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils/cli.py +46 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils/parser.py +154 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils.egg-info/PKG-INFO +84 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils.egg-info/SOURCES.txt +13 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils.egg-info/dependency_links.txt +1 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils.egg-info/entry_points.txt +2 -0
- proxyverge_utils-1.0.0/src/proxyverge_utils.egg-info/top_level.txt +1 -0
- proxyverge_utils-1.0.0/tests/test_proxyverge_utils.py +99 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ProxyVerge
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: proxyverge-utils
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Zero-dependency proxy string parser, format converter (requests, httpx, Playwright, cURL), and exit IP/header leak checker.
|
|
5
|
+
Author-email: ProxyVerge <support@proxyverge.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://proxyverge.com/tools/proxy-converter
|
|
8
|
+
Project-URL: Documentation, https://proxyverge.com/tools/my-ip
|
|
9
|
+
Project-URL: API, https://proxyverge.com/api/ip
|
|
10
|
+
Keywords: proxy,proxy-parser,proxy-converter,web-scraping,playwright,httpx,ip-checker,socks5
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# proxyverge-utils
|
|
27
|
+
|
|
28
|
+
Zero-dependency Python library & CLI for parsing proxy strings, converting formats (`requests`, `httpx`, `Playwright`, `cURL`, `url`), and checking exit IP / proxy header leaks.
|
|
29
|
+
|
|
30
|
+
- Browser-based bulk converter (100% client-side): https://proxyverge.com/tools/proxy-converter
|
|
31
|
+
- Browser IP, WebRTC & DNS leak checker: https://proxyverge.com/tools/my-ip
|
|
32
|
+
- Lightweight JSON exit IP endpoint: https://proxyverge.com/api/ip
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install proxyverge-utils
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from proxyverge_utils import parse_proxy, format_proxy, convert_batch, check_ip
|
|
44
|
+
|
|
45
|
+
# Parse colon-delimited strings (including passwords with special characters)
|
|
46
|
+
cfg = parse_proxy("198.51.100.10:8080:alice:p@ss:w/rd#1")
|
|
47
|
+
|
|
48
|
+
# Percent-encoded URL for httpx
|
|
49
|
+
httpx_url = format_proxy(cfg, "httpx")
|
|
50
|
+
# 'http://alice:p%40ss%3Aw%2Frd%231@198.51.100.10:8080'
|
|
51
|
+
|
|
52
|
+
# Dict ready for requests.get(..., proxies=...)
|
|
53
|
+
req_proxies = format_proxy("198.51.100.10:8080:alice:secret", "requests")
|
|
54
|
+
|
|
55
|
+
# Playwright proxy dict
|
|
56
|
+
pw_proxy = format_proxy("198.51.100.10:8080:alice:secret", "playwright")
|
|
57
|
+
# {'server': 'http://198.51.100.10:8080', 'username': 'alice', 'password': 'secret'}
|
|
58
|
+
|
|
59
|
+
# DNS-leak-safe cURL command for SOCKS5 (--socks5-hostname)
|
|
60
|
+
curl_cmd = format_proxy("198.51.100.10:1080:alice:secret", "curl", default_protocol="socks5")
|
|
61
|
+
|
|
62
|
+
# Batch conversion (skips empty lines and # comments)
|
|
63
|
+
urls = convert_batch("""
|
|
64
|
+
# Pool
|
|
65
|
+
198.51.100.10:8080:u1:p1
|
|
66
|
+
u2:p2@198.51.100.11:9000
|
|
67
|
+
""", fmt="url")
|
|
68
|
+
|
|
69
|
+
# Check exit IP, ASN, country, and leaked proxy headers
|
|
70
|
+
info = check_ip()
|
|
71
|
+
print(info["ip"], info["country"], info["asn"], info["has_proxy_headers"])
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## CLI Usage
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
proxyverge-utils convert "198.51.100.10:8080:user:p@ss" --format playwright
|
|
78
|
+
proxyverge-utils convert "198.51.100.10:1080:user:pass" --protocol socks5 --format curl
|
|
79
|
+
proxyverge-utils check-ip
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# proxyverge-utils
|
|
2
|
+
|
|
3
|
+
Zero-dependency Python library & CLI for parsing proxy strings, converting formats (`requests`, `httpx`, `Playwright`, `cURL`, `url`), and checking exit IP / proxy header leaks.
|
|
4
|
+
|
|
5
|
+
- Browser-based bulk converter (100% client-side): https://proxyverge.com/tools/proxy-converter
|
|
6
|
+
- Browser IP, WebRTC & DNS leak checker: https://proxyverge.com/tools/my-ip
|
|
7
|
+
- Lightweight JSON exit IP endpoint: https://proxyverge.com/api/ip
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install proxyverge-utils
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from proxyverge_utils import parse_proxy, format_proxy, convert_batch, check_ip
|
|
19
|
+
|
|
20
|
+
# Parse colon-delimited strings (including passwords with special characters)
|
|
21
|
+
cfg = parse_proxy("198.51.100.10:8080:alice:p@ss:w/rd#1")
|
|
22
|
+
|
|
23
|
+
# Percent-encoded URL for httpx
|
|
24
|
+
httpx_url = format_proxy(cfg, "httpx")
|
|
25
|
+
# 'http://alice:p%40ss%3Aw%2Frd%231@198.51.100.10:8080'
|
|
26
|
+
|
|
27
|
+
# Dict ready for requests.get(..., proxies=...)
|
|
28
|
+
req_proxies = format_proxy("198.51.100.10:8080:alice:secret", "requests")
|
|
29
|
+
|
|
30
|
+
# Playwright proxy dict
|
|
31
|
+
pw_proxy = format_proxy("198.51.100.10:8080:alice:secret", "playwright")
|
|
32
|
+
# {'server': 'http://198.51.100.10:8080', 'username': 'alice', 'password': 'secret'}
|
|
33
|
+
|
|
34
|
+
# DNS-leak-safe cURL command for SOCKS5 (--socks5-hostname)
|
|
35
|
+
curl_cmd = format_proxy("198.51.100.10:1080:alice:secret", "curl", default_protocol="socks5")
|
|
36
|
+
|
|
37
|
+
# Batch conversion (skips empty lines and # comments)
|
|
38
|
+
urls = convert_batch("""
|
|
39
|
+
# Pool
|
|
40
|
+
198.51.100.10:8080:u1:p1
|
|
41
|
+
u2:p2@198.51.100.11:9000
|
|
42
|
+
""", fmt="url")
|
|
43
|
+
|
|
44
|
+
# Check exit IP, ASN, country, and leaked proxy headers
|
|
45
|
+
info = check_ip()
|
|
46
|
+
print(info["ip"], info["country"], info["asn"], info["has_proxy_headers"])
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## CLI Usage
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
proxyverge-utils convert "198.51.100.10:8080:user:p@ss" --format playwright
|
|
53
|
+
proxyverge-utils convert "198.51.100.10:1080:user:pass" --protocol socks5 --format curl
|
|
54
|
+
proxyverge-utils check-ip
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "proxyverge-utils"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Zero-dependency proxy string parser, format converter (requests, httpx, Playwright, cURL), and exit IP/header leak checker."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "ProxyVerge", email = "support@proxyverge.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["proxy", "proxy-parser", "proxy-converter", "web-scraping", "playwright", "httpx", "ip-checker", "socks5"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
]
|
|
28
|
+
dependencies = []
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://proxyverge.com/tools/proxy-converter"
|
|
32
|
+
Documentation = "https://proxyverge.com/tools/my-ip"
|
|
33
|
+
API = "https://proxyverge.com/api/ip"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
proxyverge-utils = "proxyverge_utils.cli:main"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, Optional, Union
|
|
5
|
+
from urllib import request as urllib_request
|
|
6
|
+
|
|
7
|
+
from .parser import ProxyConfig, format_proxy
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def check_ip(
|
|
11
|
+
proxy: Optional[Union[str, ProxyConfig]] = None,
|
|
12
|
+
endpoint: str = "https://proxyverge.com/api/ip",
|
|
13
|
+
timeout: float = 10.0,
|
|
14
|
+
) -> dict[str, Any]:
|
|
15
|
+
"""Fetch exit IP, ASN, geolocation, and proxy header leak signals from https://proxyverge.com/api/ip."""
|
|
16
|
+
handlers = []
|
|
17
|
+
if proxy:
|
|
18
|
+
proxies_dict = format_proxy(proxy, fmt="requests")
|
|
19
|
+
handlers.append(urllib_request.ProxyHandler(proxies_dict))
|
|
20
|
+
opener = urllib_request.build_opener(*handlers)
|
|
21
|
+
req = urllib_request.Request(endpoint, headers={"Accept": "application/json", "User-Agent": "proxyverge-utils/1.0.0"})
|
|
22
|
+
with opener.open(req, timeout=timeout) as resp:
|
|
23
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
24
|
+
headers_list = data.get("proxyHeaders") if isinstance(data.get("proxyHeaders"), list) else []
|
|
25
|
+
data["proxyHeaders"] = headers_list
|
|
26
|
+
data["has_proxy_headers"] = len(headers_list) > 0
|
|
27
|
+
return data
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from .checker import check_ip
|
|
8
|
+
from .parser import format_proxy
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main(argv: list[str] | None = None) -> int:
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
prog="proxyverge-utils",
|
|
14
|
+
description="Convert proxy formats and check exit IP / header leaks (https://proxyverge.com/tools/proxy-converter).",
|
|
15
|
+
)
|
|
16
|
+
sub = parser.add_subparsers(dest="command")
|
|
17
|
+
|
|
18
|
+
p_conv = sub.add_parser("convert", help="Convert a proxy string to a target format")
|
|
19
|
+
p_conv.add_argument("proxy", help="Proxy string (e.g. host:port:user:pass)")
|
|
20
|
+
p_conv.add_argument(
|
|
21
|
+
"--format",
|
|
22
|
+
default="url",
|
|
23
|
+
choices=["url", "requests", "httpx", "playwright", "curl", "host-port-user-pass", "user-pass-host-port", "json"],
|
|
24
|
+
)
|
|
25
|
+
p_conv.add_argument("--protocol", default="http")
|
|
26
|
+
|
|
27
|
+
p_ip = sub.add_parser("check-ip", help="Check exit IP via https://proxyverge.com/api/ip")
|
|
28
|
+
p_ip.add_argument("--proxy", default=None, help="Optional HTTP/HTTPS proxy string")
|
|
29
|
+
p_ip.add_argument("--endpoint", default="https://proxyverge.com/api/ip")
|
|
30
|
+
|
|
31
|
+
args = parser.parse_args(argv)
|
|
32
|
+
if args.command == "convert":
|
|
33
|
+
out = format_proxy(args.proxy, fmt=args.format, default_protocol=args.protocol)
|
|
34
|
+
print(out if isinstance(out, str) else json.dumps(out, indent=2))
|
|
35
|
+
return 0
|
|
36
|
+
if args.command == "check-ip":
|
|
37
|
+
data = check_ip(proxy=args.proxy, endpoint=args.endpoint)
|
|
38
|
+
print(json.dumps(data, indent=2))
|
|
39
|
+
return 0
|
|
40
|
+
|
|
41
|
+
parser.print_help()
|
|
42
|
+
return 0
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
sys.exit(main())
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, asdict
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any, Union
|
|
7
|
+
from urllib.parse import quote, unquote
|
|
8
|
+
|
|
9
|
+
SUPPORTED_PROTOCOLS = {"http", "https", "socks4", "socks5", "socks5h"}
|
|
10
|
+
_PROTO_RE = re.compile(r"^([a-z0-9]+)://(.+)$", re.IGNORECASE)
|
|
11
|
+
_HOSTPORT_RE = re.compile(r"^(\[[^\]]+\]|[^:/\s]+):(\d{1,5})$")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class ProxyConfig:
|
|
16
|
+
protocol: str
|
|
17
|
+
host: str
|
|
18
|
+
port: int
|
|
19
|
+
username: str = ""
|
|
20
|
+
password: str = ""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _normalize_protocol(protocol: str = "http") -> str:
|
|
24
|
+
clean = (protocol or "http").strip().lower().removesuffix("://")
|
|
25
|
+
if clean not in SUPPORTED_PROTOCOLS:
|
|
26
|
+
raise ValueError(f"Unsupported proxy protocol: {protocol}")
|
|
27
|
+
return clean
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _validate_port(raw_port: Union[str, int]) -> int:
|
|
31
|
+
try:
|
|
32
|
+
port = int(raw_port)
|
|
33
|
+
except (TypeError, ValueError) as exc:
|
|
34
|
+
raise ValueError(f"Invalid proxy port: {raw_port}") from exc
|
|
35
|
+
if port < 1 or port > 65535:
|
|
36
|
+
raise ValueError(f"Invalid proxy port: {raw_port}")
|
|
37
|
+
return port
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_proxy(
|
|
41
|
+
raw: Union[str, ProxyConfig], default_protocol: str = "http"
|
|
42
|
+
) -> ProxyConfig:
|
|
43
|
+
"""Parse a proxy string in host:port, host:port:user:pass, user:pass@host:port, or URL format."""
|
|
44
|
+
if isinstance(raw, ProxyConfig):
|
|
45
|
+
return ProxyConfig(
|
|
46
|
+
protocol=_normalize_protocol(raw.protocol or default_protocol),
|
|
47
|
+
host=raw.host.strip(),
|
|
48
|
+
port=_validate_port(raw.port),
|
|
49
|
+
username=raw.username or "",
|
|
50
|
+
password=raw.password or "",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
text = (raw or "").strip()
|
|
54
|
+
if not text:
|
|
55
|
+
raise ValueError("Proxy string cannot be empty")
|
|
56
|
+
|
|
57
|
+
proto_match = _PROTO_RE.match(text)
|
|
58
|
+
protocol = _normalize_protocol(proto_match.group(1) if proto_match else default_protocol)
|
|
59
|
+
body = (proto_match.group(2) if proto_match else text).rstrip("/")
|
|
60
|
+
|
|
61
|
+
# Format: user:pass@host:port (only when RHS after last '@' is a valid host:port)
|
|
62
|
+
at_idx = body.rfind("@")
|
|
63
|
+
if at_idx != -1:
|
|
64
|
+
auth_part = body[:at_idx]
|
|
65
|
+
host_port_part = body[at_idx + 1 :]
|
|
66
|
+
hp_match = _HOSTPORT_RE.match(host_port_part)
|
|
67
|
+
if hp_match:
|
|
68
|
+
if ":" in auth_part:
|
|
69
|
+
u_raw, p_raw = auth_part.split(":", 1)
|
|
70
|
+
username, password = unquote(u_raw), unquote(p_raw)
|
|
71
|
+
else:
|
|
72
|
+
username, password = unquote(auth_part), ""
|
|
73
|
+
host = hp_match.group(1).strip("[]").strip()
|
|
74
|
+
port = _validate_port(hp_match.group(2))
|
|
75
|
+
if host:
|
|
76
|
+
return ProxyConfig(protocol=protocol, host=host, port=port, username=username, password=password)
|
|
77
|
+
|
|
78
|
+
# Format: host:port or host:port:user:pass (passwords may contain ':')
|
|
79
|
+
parts = body.split(":")
|
|
80
|
+
if len(parts) == 2:
|
|
81
|
+
host = parts[0].strip()
|
|
82
|
+
port = _validate_port(parts[1])
|
|
83
|
+
if not host:
|
|
84
|
+
raise ValueError(f"Missing host in proxy: {text}")
|
|
85
|
+
return ProxyConfig(protocol=protocol, host=host, port=port)
|
|
86
|
+
|
|
87
|
+
if len(parts) >= 4:
|
|
88
|
+
host = parts[0].strip()
|
|
89
|
+
port = _validate_port(parts[1])
|
|
90
|
+
username = parts[2]
|
|
91
|
+
password = ":".join(parts[3:])
|
|
92
|
+
if not host:
|
|
93
|
+
raise ValueError(f"Missing host in proxy: {text}")
|
|
94
|
+
return ProxyConfig(protocol=protocol, host=host, port=port, username=username, password=password)
|
|
95
|
+
|
|
96
|
+
raise ValueError(f"Unrecognized proxy format: {text}")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def format_proxy(
|
|
100
|
+
proxy: Union[str, ProxyConfig],
|
|
101
|
+
fmt: str = "url",
|
|
102
|
+
default_protocol: str = "http",
|
|
103
|
+
) -> Any:
|
|
104
|
+
"""Convert a proxy string or ProxyConfig into url, requests, httpx, playwright, curl, json, etc."""
|
|
105
|
+
p = parse_proxy(proxy, default_protocol=default_protocol)
|
|
106
|
+
host_display = f"[{p.host}]" if ":" in p.host else p.host
|
|
107
|
+
if p.username or p.password:
|
|
108
|
+
auth = f"{quote(p.username, safe='')}:{quote(p.password, safe='')}@"
|
|
109
|
+
else:
|
|
110
|
+
auth = ""
|
|
111
|
+
url = f"{p.protocol}://{auth}{host_display}:{p.port}"
|
|
112
|
+
|
|
113
|
+
kind = (fmt or "url").strip().lower()
|
|
114
|
+
if kind in ("url", "httpx"):
|
|
115
|
+
return url
|
|
116
|
+
if kind == "requests":
|
|
117
|
+
return {"http": url, "https": url}
|
|
118
|
+
if kind == "host-port-user-pass":
|
|
119
|
+
if p.username or p.password:
|
|
120
|
+
return f"{p.host}:{p.port}:{p.username}:{p.password}"
|
|
121
|
+
return f"{p.host}:{p.port}"
|
|
122
|
+
if kind == "user-pass-host-port":
|
|
123
|
+
if p.username or p.password:
|
|
124
|
+
return f"{p.username}:{p.password}@{host_display}:{p.port}"
|
|
125
|
+
return f"{host_display}:{p.port}"
|
|
126
|
+
if kind == "playwright":
|
|
127
|
+
server_proto = "socks5" if p.protocol == "socks5h" else p.protocol
|
|
128
|
+
cfg = {"server": f"{server_proto}://{host_display}:{p.port}"}
|
|
129
|
+
if p.username:
|
|
130
|
+
cfg["username"] = p.username
|
|
131
|
+
if p.password:
|
|
132
|
+
cfg["password"] = p.password
|
|
133
|
+
return cfg
|
|
134
|
+
if kind == "curl":
|
|
135
|
+
if p.protocol in ("socks5", "socks5h"):
|
|
136
|
+
auth_flag = f' -U "{p.username}:{p.password}"' if (p.username or p.password) else ""
|
|
137
|
+
return f'curl -s --socks5-hostname "{host_display}:{p.port}"{auth_flag} https://proxyverge.com/api/ip'
|
|
138
|
+
return f'curl -s -x "{url}" https://proxyverge.com/api/ip'
|
|
139
|
+
if kind == "json":
|
|
140
|
+
return json.dumps(asdict(p))
|
|
141
|
+
raise ValueError(f"Unsupported output format: {fmt}")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def convert_batch(
|
|
145
|
+
text: str, fmt: str = "url", default_protocol: str = "http"
|
|
146
|
+
) -> list[Any]:
|
|
147
|
+
"""Convert a newline-delimited list of proxy strings, ignoring blank lines and '#' comments."""
|
|
148
|
+
results: list[Any] = []
|
|
149
|
+
for raw_line in (text or "").splitlines():
|
|
150
|
+
line = raw_line.strip()
|
|
151
|
+
if not line or line.startswith("#"):
|
|
152
|
+
continue
|
|
153
|
+
results.append(format_proxy(line, fmt=fmt, default_protocol=default_protocol))
|
|
154
|
+
return results
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: proxyverge-utils
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Zero-dependency proxy string parser, format converter (requests, httpx, Playwright, cURL), and exit IP/header leak checker.
|
|
5
|
+
Author-email: ProxyVerge <support@proxyverge.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://proxyverge.com/tools/proxy-converter
|
|
8
|
+
Project-URL: Documentation, https://proxyverge.com/tools/my-ip
|
|
9
|
+
Project-URL: API, https://proxyverge.com/api/ip
|
|
10
|
+
Keywords: proxy,proxy-parser,proxy-converter,web-scraping,playwright,httpx,ip-checker,socks5
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# proxyverge-utils
|
|
27
|
+
|
|
28
|
+
Zero-dependency Python library & CLI for parsing proxy strings, converting formats (`requests`, `httpx`, `Playwright`, `cURL`, `url`), and checking exit IP / proxy header leaks.
|
|
29
|
+
|
|
30
|
+
- Browser-based bulk converter (100% client-side): https://proxyverge.com/tools/proxy-converter
|
|
31
|
+
- Browser IP, WebRTC & DNS leak checker: https://proxyverge.com/tools/my-ip
|
|
32
|
+
- Lightweight JSON exit IP endpoint: https://proxyverge.com/api/ip
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install proxyverge-utils
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from proxyverge_utils import parse_proxy, format_proxy, convert_batch, check_ip
|
|
44
|
+
|
|
45
|
+
# Parse colon-delimited strings (including passwords with special characters)
|
|
46
|
+
cfg = parse_proxy("198.51.100.10:8080:alice:p@ss:w/rd#1")
|
|
47
|
+
|
|
48
|
+
# Percent-encoded URL for httpx
|
|
49
|
+
httpx_url = format_proxy(cfg, "httpx")
|
|
50
|
+
# 'http://alice:p%40ss%3Aw%2Frd%231@198.51.100.10:8080'
|
|
51
|
+
|
|
52
|
+
# Dict ready for requests.get(..., proxies=...)
|
|
53
|
+
req_proxies = format_proxy("198.51.100.10:8080:alice:secret", "requests")
|
|
54
|
+
|
|
55
|
+
# Playwright proxy dict
|
|
56
|
+
pw_proxy = format_proxy("198.51.100.10:8080:alice:secret", "playwright")
|
|
57
|
+
# {'server': 'http://198.51.100.10:8080', 'username': 'alice', 'password': 'secret'}
|
|
58
|
+
|
|
59
|
+
# DNS-leak-safe cURL command for SOCKS5 (--socks5-hostname)
|
|
60
|
+
curl_cmd = format_proxy("198.51.100.10:1080:alice:secret", "curl", default_protocol="socks5")
|
|
61
|
+
|
|
62
|
+
# Batch conversion (skips empty lines and # comments)
|
|
63
|
+
urls = convert_batch("""
|
|
64
|
+
# Pool
|
|
65
|
+
198.51.100.10:8080:u1:p1
|
|
66
|
+
u2:p2@198.51.100.11:9000
|
|
67
|
+
""", fmt="url")
|
|
68
|
+
|
|
69
|
+
# Check exit IP, ASN, country, and leaked proxy headers
|
|
70
|
+
info = check_ip()
|
|
71
|
+
print(info["ip"], info["country"], info["asn"], info["has_proxy_headers"])
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## CLI Usage
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
proxyverge-utils convert "198.51.100.10:8080:user:p@ss" --format playwright
|
|
78
|
+
proxyverge-utils convert "198.51.100.10:1080:user:pass" --protocol socks5 --format curl
|
|
79
|
+
proxyverge-utils check-ip
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/proxyverge_utils/__init__.py
|
|
5
|
+
src/proxyverge_utils/checker.py
|
|
6
|
+
src/proxyverge_utils/cli.py
|
|
7
|
+
src/proxyverge_utils/parser.py
|
|
8
|
+
src/proxyverge_utils.egg-info/PKG-INFO
|
|
9
|
+
src/proxyverge_utils.egg-info/SOURCES.txt
|
|
10
|
+
src/proxyverge_utils.egg-info/dependency_links.txt
|
|
11
|
+
src/proxyverge_utils.egg-info/entry_points.txt
|
|
12
|
+
src/proxyverge_utils.egg-info/top_level.txt
|
|
13
|
+
tests/test_proxyverge_utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
proxyverge_utils
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import unittest
|
|
4
|
+
from unittest.mock import patch
|
|
5
|
+
|
|
6
|
+
from proxyverge_utils import ProxyConfig, parse_proxy, format_proxy, convert_batch, check_ip
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TestProxyVergeUtils(unittest.TestCase):
|
|
10
|
+
def test_parse_colon_format_with_special_password(self):
|
|
11
|
+
cfg = parse_proxy("198.51.100.10:8080:alice:p@ss:w/rd#1")
|
|
12
|
+
self.assertEqual(
|
|
13
|
+
cfg,
|
|
14
|
+
ProxyConfig(
|
|
15
|
+
protocol="http",
|
|
16
|
+
host="198.51.100.10",
|
|
17
|
+
port=8080,
|
|
18
|
+
username="alice",
|
|
19
|
+
password="p@ss:w/rd#1",
|
|
20
|
+
),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def test_parse_url_encoded_socks5h(self):
|
|
24
|
+
cfg = parse_proxy("socks5h://alice:p%40ss%3A1@gate.example.com:1080")
|
|
25
|
+
self.assertEqual(cfg.protocol, "socks5h")
|
|
26
|
+
self.assertEqual(cfg.host, "gate.example.com")
|
|
27
|
+
self.assertEqual(cfg.port, 1080)
|
|
28
|
+
self.assertEqual(cfg.username, "alice")
|
|
29
|
+
self.assertEqual(cfg.password, "p@ss:1")
|
|
30
|
+
|
|
31
|
+
def test_format_outputs(self):
|
|
32
|
+
self.assertEqual(
|
|
33
|
+
format_proxy("198.51.100.10:8080:alice:p@ss:w/rd#1", "url"),
|
|
34
|
+
"http://alice:p%40ss%3Aw%2Frd%231@198.51.100.10:8080",
|
|
35
|
+
)
|
|
36
|
+
self.assertEqual(
|
|
37
|
+
format_proxy("198.51.100.10:8080:alice:secret", "requests"),
|
|
38
|
+
{
|
|
39
|
+
"http": "http://alice:secret@198.51.100.10:8080",
|
|
40
|
+
"https": "http://alice:secret@198.51.100.10:8080",
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
self.assertEqual(
|
|
44
|
+
format_proxy("198.51.100.10:8080:alice:secret", "playwright"),
|
|
45
|
+
{"server": "http://198.51.100.10:8080", "username": "alice", "password": "secret"},
|
|
46
|
+
)
|
|
47
|
+
self.assertEqual(
|
|
48
|
+
format_proxy("198.51.100.10:1080:alice:secret", "curl", default_protocol="socks5"),
|
|
49
|
+
'curl -s --socks5-hostname "198.51.100.10:1080" -U "alice:secret" https://proxyverge.com/api/ip',
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def test_convert_batch(self):
|
|
53
|
+
out = convert_batch(
|
|
54
|
+
"""
|
|
55
|
+
# pool
|
|
56
|
+
198.51.100.10:8080:u1:p1
|
|
57
|
+
|
|
58
|
+
u2:p2@198.51.100.11:9000
|
|
59
|
+
""",
|
|
60
|
+
fmt="url",
|
|
61
|
+
)
|
|
62
|
+
self.assertEqual(
|
|
63
|
+
out,
|
|
64
|
+
[
|
|
65
|
+
"http://u1:p1@198.51.100.10:8080",
|
|
66
|
+
"http://u2:p2@198.51.100.11:9000",
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
def test_check_ip_mocked(self):
|
|
71
|
+
payload = json.dumps(
|
|
72
|
+
{
|
|
73
|
+
"ip": "203.0.113.5",
|
|
74
|
+
"version": 4,
|
|
75
|
+
"country": "US",
|
|
76
|
+
"asn": 64512,
|
|
77
|
+
"proxyHeaders": ["Via"],
|
|
78
|
+
}
|
|
79
|
+
).encode("utf-8")
|
|
80
|
+
|
|
81
|
+
class FakeResp(io.BytesIO):
|
|
82
|
+
def __enter__(self):
|
|
83
|
+
return self
|
|
84
|
+
|
|
85
|
+
def __exit__(self, *args):
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
class FakeOpener:
|
|
89
|
+
def open(self, req, timeout=10.0):
|
|
90
|
+
return FakeResp(payload)
|
|
91
|
+
|
|
92
|
+
with patch("proxyverge_utils.checker.urllib_request.build_opener", return_value=FakeOpener()):
|
|
93
|
+
res = check_ip()
|
|
94
|
+
self.assertEqual(res["ip"], "203.0.113.5")
|
|
95
|
+
self.assertTrue(res["has_proxy_headers"])
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
unittest.main()
|