import requests
import os
from datetime import datetime
# API credentials
API_PUBLIC_KEY = "your_public_key"
API_PRIVATE_KEY = "your_private_key"
BASE_URL = "https://api.pingproxies.com/1.0/public"
# Headers for authentication
headers = {
"X-API-Public-Key": API_PUBLIC_KEY,
"X-API-Private-Key": API_PRIVATE_KEY
}
def get_static_proxy_list():
"""
Retrieve all static proxies using the list_by_search endpoint.
Note: You can modify format_type and protocol parameters to get different formats:
- format_type options: "standard", "http", "socks5", "socks5h"
- protocol options: "http" or "socks5"
Returns:
List of formatted proxy strings
"""
# Set up the parameters for list_by_search
params = {
"list_format": "standard", # You can change this to "http", "socks5", or "socks5h"
"list_protocol": "http", # You can change this to "socks5"
"list_version": "ipv4", # IP version (ipv4 or ipv6)
"list_authentication": "username_and_password" # Authentication type
}
# Make request to the list_by_search endpoint
response = requests.get(
f"{BASE_URL}/user/proxy/list_by_search",
params=params,
headers=headers
)
if response.status_code != 200:
print(f"Error: {response.status_code}")
return []
data = response.json()
# The list endpoint returns the formatted proxies directly in data
proxy_list = data["data"]
print(f"Successfully retrieved {len(proxy_list)} formatted proxies")
return proxy_list
def export_to_file(proxy_list):
"""Export proxy list to a file."""
# Create a default filename with timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"proxies_{timestamp}.txt"
# Write the proxy list to a file
with open(filename, "w") as file:
for proxy in proxy_list:
file.write(f"{proxy}\n")
print(f"Exported {len(proxy_list)} proxies to {filename}")
return filename
# Example usage
if __name__ == "__main__":
# Get proxies in standard format
proxy_list = get_static_proxy_list()
# Export to file
if proxy_list:
export_to_file(proxy_list)
# Print sample output
if proxy_list:
print(f"\nSample output: {proxy_list[0]}")