Untitled
unknown
plain_text
a year ago
3.2 kB
1
Indexable
Never
import subprocess import re import sys from termcolor import colored import setproctitle setproctitle.setproctitle("Dns Resolver") sys.stdin.reconfigure(encoding='utf-8') dns_servers = [ {'name': 'Shecan', 'primary': '178.22.122.100', 'secondary': '185.51.200.2'}, {'name': 'Radar', 'primary': '10.202.10.10', 'secondary': '10.202.10.11'}, {'name': 'Electero', 'primary': '78.157.42.101', 'secondary': '78.157.42.100'}, {'name': 'Google', 'primary': '8.8.8.8', 'secondary': '8.8.4.4'}, {'name': 'Clear Dns', 'primary': '', 'secondary': ''} ] print('Available DNS servers:') for index, dns_server in enumerate(dns_servers): print(f"{index + 1}. {dns_server['name']}") while True: selection = input('Please select a DNS server 1-5 (for custom press 6): ') if selection in ['1', '2', '3', '4', '5', '6']: break print('Invalid selection. Please choose a number between 1 and 6.') if selection == '1': primary_dns = dns_servers[0]['primary'] secondary_dns = dns_servers[0]['secondary'] elif selection == '2': primary_dns = dns_servers[1]['primary'] secondary_dns = dns_servers[1]['secondary'] elif selection == '3': primary_dns = dns_servers[2]['primary'] secondary_dns = dns_servers[2]['secondary'] elif selection == '4': primary_dns = dns_servers[3]['primary'] secondary_dns = dns_servers[3]['secondary'] elif selection == '5': primary_dns = dns_servers[4]['primary'] secondary_dns = dns_servers[4]['secondary'] elif selection == '6': while True: primary_dns = input('Enter the primary DNS server IP address: ') secondary_dns = input('Enter the secondary DNS server IP address (leave blank if not applicable): ') if primary_dns and not re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', primary_dns): print('Invalid IP address format. Please try again.') elif secondary_dns and not re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', secondary_dns): print('Invalid IP address format. Please try again.') else: break output = subprocess.check_output('netsh interface show interface', shell=True) interface_name = re.search(b'Connected.* (.+?)\n', output).group(1).decode() if primary_dns and secondary_dns: windows_command_primary = f"netsh interface ipv4 set dns name=\"{interface_name}\" static {primary_dns} primary" windows_command_secondary = f"netsh interface ipv4 add dns name=\"{interface_name}\" {secondary_dns} index=2" else: windows_command_primary = f"netsh interface ipv4 set dns name=\"{interface_name}\" dhcp" windows_command_secondary = "" windows_command_flushdns = "ipconfig /flushdns" try: subprocess.run(windows_command_primary, check=True, shell=True) if secondary_dns: subprocess.run(windows_command_secondary, check=True, shell=True) subprocess.run(windows_command_flushdns, check=True, shell=True) print(colored('DNS servers set successfully!', 'green')) except subprocess.CalledProcessError as error: print(colored('Failed to set DNS servers! Please try again.', 'red')) input("Press Enter to exit...")