EasyConnect custom routing table

2020/07/02

        Nowadays, many schools and enterprises choose EasyConnect socket as their remote network connection solution. However, EasyConnect's client highly supports server-side customization, in which server-side access IP permissions and IP mapping can be carefully defined by the server. In contrast, the client has poor transparency. Almost all configuration is automatically done by the client for the user, and there are no viewing and changing options.

        When I use EasyConnect to remotely access the school campus network, an embarrassing problem arises: EasyConnect acts as a global proxy by default, and I just want to use EasyConnect to access CNKI or campus network resources, and do not want to be slowed down by proxies in other applications. Trying to set up EasyConnect, it offers no useful options at all. So is there any way to limit the proxy range of EasyConnect from the bottom up?

        The answer is yes. (The following applies to Windows systems)


        Method: Modify routing table configuration

        You can see the current routing table configuration by entering the following command on the command line

route print

        Later, I discovered that EasyConnect on campus has acted as a proxy for all IP addresses.

        Since EasyConnect cannot be modified internally, we can delete its proxy routing table after it becomes a proxy!

        Because I am not familiar with cmd (qwq), the specific implementation uses python to entrain and call cmd. The following code implements the function of searching the proxy for the 172.29.*.* address from the routing table, then deleting the relevant proxy, and finally adding the routes address to the proxy.

import os
import re

routes = ['8.8.8.8',]

txt = os.popen('route print 172.29.*')
txt = txt.read()
result = re.search(r' 172.29.* (172.29.*) (172.29.*) ',txt)
if result:
    gate = result.group(1).strip()
    inter = result.group(2).strip()
    print(f'网关:{gate} 接口:{inter}')

    txt = os.popen('route print')
    txt = txt.readlines()
    for line in txt:
        result = re.split('[ ]+', line.strip())
        if len(result)==5 and result[2].strip()==gate and result[3].strip()==inter:
            para1 = result[0].strip()
            os.system(f'route delete {para1} {gate}')
    
    for route in routes:
        os.system(f'route add {route} mask 255.255.255.255 {gate}')
else:
    print('如果重复运行该程序,因主要网关已被清理将无法找到VPN网关,请尝试优化程序或重启VPN。')

       Since some commands require administrator rights, I usually like to write bat to run py files with one click. The bat code is given below:

@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
python vpn.py
pause

        ​ ​ ​The Python file name is vpn.py.


        The above involves a large number of Windows system command calls, and the Linux platform needs to make some corresponding modifications.

Guess you like

Origin blog.csdn.net/hizcard/article/details/107095362