mirror of
				https://github.com/taixingyiji/openit.git
				synced 2025-11-04 04:52:30 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			164 lines
		
	
	
		
			7.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			164 lines
		
	
	
		
			7.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import yaml
 | 
						|
import socket
 | 
						|
import maxminddb
 | 
						|
from tqdm import tqdm
 | 
						|
import flag
 | 
						|
 | 
						|
 | 
						|
def push(list):
 | 
						|
    ss_omit_ip_dupe = 0
 | 
						|
    ss_omit_cipher_unsupported = 0
 | 
						|
    ss_supported_ciphers = ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm',
 | 
						|
                            'aes-128-cfb', 'aes-192-cfb', 'aes-256-cfb', 'aes-128-ctr', 'aes-192-ctr', 'aes-256-ctr',
 | 
						|
                            'rc4-md5', 'chacha20-ietf', 'xchacha20', 'chacha20-ietf-poly1305',
 | 
						|
                            'xchacha20-ietf-poly1305']
 | 
						|
    ssr_supported_obfs = ['plain', 'http_simple', 'http_post', 'random_head', 'tls1.2_ticket_auth',
 | 
						|
                          'tls1.2_ticket_fastauth']
 | 
						|
    ssr_supported_protocol = ['origin', 'auth_sha1_v4', 'auth_aes128_md5', 'auth_aes128_sha1', 'auth_chain_a',
 | 
						|
                              'auth_chain_b']
 | 
						|
    vmess_supported_ciphers = ['auto', 'aes-128-gcm', 'chacha20-poly1305', 'none']
 | 
						|
    passlist = []
 | 
						|
    iplist = {}
 | 
						|
    passlist = []
 | 
						|
    count = 1
 | 
						|
    clash = {'proxies': [], 'proxy-groups': [
 | 
						|
            {'name': 'automatic', 'type': 'url-test', 'proxies': [], 'url': 'https://www.google.com/favicon.ico',
 | 
						|
             'interval': 300}, {'name': '🌐 Proxy', 'type': 'select', 'proxies': ['automatic']}],
 | 
						|
             'rules': ['MATCH,🌐 Proxy']}
 | 
						|
    with maxminddb.open_database('Country.mmdb') as countrify:
 | 
						|
        for i in tqdm(range(int(len(list))), desc="Parse"):
 | 
						|
            try:
 | 
						|
                x = list[i]
 | 
						|
                authentication = ''
 | 
						|
                try:
 | 
						|
                    ip = str(socket.gethostbyname(x["server"]))
 | 
						|
                except:
 | 
						|
                    ip = x['server']
 | 
						|
                try:
 | 
						|
                    country = str(countrify.get(ip)['country']['iso_code'])
 | 
						|
                except:
 | 
						|
                    country = 'UN'
 | 
						|
                if x['type'] == 'ss':
 | 
						|
                    try:
 | 
						|
                        if x['cipher'] not in ss_supported_ciphers:
 | 
						|
                            ss_omit_cipher_unsupported = ss_omit_cipher_unsupported + 1
 | 
						|
                            continue
 | 
						|
                        if country != 'CN':
 | 
						|
                            if ip in iplist:
 | 
						|
                                ss_omit_ip_dupe = ss_omit_ip_dupe + 1
 | 
						|
                                continue
 | 
						|
                            else:
 | 
						|
                                iplist.append(ip)
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'SSS'
 | 
						|
                        authentication = 'password'
 | 
						|
                    except:
 | 
						|
                        print("shit went wrong " + x)
 | 
						|
                        continue
 | 
						|
                elif x['type'] == 'ssr':
 | 
						|
                    try:
 | 
						|
                        if x['cipher'] not in ss_supported_ciphers:
 | 
						|
                            continue
 | 
						|
                        if x['obfs'] not in ssr_supported_obfs:
 | 
						|
                            continue
 | 
						|
                        if x['protocol'] not in ssr_supported_protocol:
 | 
						|
                            continue
 | 
						|
                        if country != 'CN':
 | 
						|
                            if ip in iplist:
 | 
						|
                                continue
 | 
						|
                            else:
 | 
						|
                                iplist.append(ip)
 | 
						|
                        authentication = 'password'
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'SSR'
 | 
						|
                    except:
 | 
						|
                        continue
 | 
						|
                elif x['type'] == 'vmess':
 | 
						|
                    try:
 | 
						|
                        if 'udp' in x:
 | 
						|
                            if x['udp'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'tls' in x:
 | 
						|
                            if x['tls'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'skip-cert-verify' in x:
 | 
						|
                            if x['skip-cert-verify'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'cipher' not in vmess_supported_ciphers:
 | 
						|
                            continue
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'VMS'
 | 
						|
                        authentication = 'uuid'
 | 
						|
                    except:
 | 
						|
                        print(x)
 | 
						|
                        continue
 | 
						|
                elif x['type'] == 'trojan':
 | 
						|
                    try:
 | 
						|
                        if 'udp' in x:
 | 
						|
                            if x['udp'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'skip-cert-verify' in x:
 | 
						|
                            if x['skip-cert-verify'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'TJN'
 | 
						|
                        authentication = 'password'
 | 
						|
                    except:
 | 
						|
                        continue
 | 
						|
                elif x['type'] == 'snell':
 | 
						|
                    try:
 | 
						|
                        if 'udp' in x:
 | 
						|
                            if x['udp'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'skip-cert-verify' in x:
 | 
						|
                            if x['skip-cert-verify'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'SNL'
 | 
						|
                        authentication = 'psk'
 | 
						|
                    except:
 | 
						|
                        continue
 | 
						|
                elif x['type'] == 'http':
 | 
						|
                    try:
 | 
						|
                        if 'tls' in x:
 | 
						|
                            if x['tls'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'HTT'
 | 
						|
                        authentication = 'userpass'
 | 
						|
                    except:
 | 
						|
                        continue
 | 
						|
                elif x['type'] == 'socks5':
 | 
						|
                    try:
 | 
						|
                        if 'tls' in x:
 | 
						|
                            if x['tls'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'udp' in x:
 | 
						|
                            if x['udp'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        if 'skip-cert-verify' in x:
 | 
						|
                            if x['skip-cert-verify'] not in [False, True]:
 | 
						|
                                continue
 | 
						|
                        x['name'] = str(flag.flag(country)) + ' ' + str(country) + ' ' + str(count) + ' ' + 'SK5'
 | 
						|
                        authentication = 'userpass'
 | 
						|
                    except:
 | 
						|
                        continue
 | 
						|
                else:
 | 
						|
                    print(x)
 | 
						|
                    print('unsupported')
 | 
						|
                    continue
 | 
						|
                if ip in iplist:
 | 
						|
                    if country != 'CN':
 | 
						|
                        continue
 | 
						|
                    else:
 | 
						|
                        if x[authentication] in passlist:
 | 
						|
                            continue
 | 
						|
                        else:
 | 
						|
                            passlist.append(x['authentication'])
 | 
						|
                            pass
 | 
						|
                clash['proxies'].append(x)
 | 
						|
                clash['proxy-groups'][0]['proxies'].append(x['name'])
 | 
						|
                clash['proxy-groups'][1]['proxies'].append(x['name'])
 | 
						|
                count = count + 1
 | 
						|
            except:
 | 
						|
                continue
 | 
						|
                # print(list[i])
 | 
						|
                # pass
 | 
						|
    print(ss_omit_ip_dupe)
 | 
						|
    with open('output.yaml', 'w') as writer:
 | 
						|
        yaml.dump(clash, writer, sort_keys=False)
 |