InvisibleManVPN / InvisibleMan-TUN

Tunneling service for Invisible Man applications (uses tun2socks and wintun)
MIT License
6 stars 1 forks source link

Hello I want a new feature plz to implement tun in any language without opening new terminal windows #7

Closed hosseinkhojany closed 1 year ago

hosseinkhojany commented 1 year ago

When I run invisibleman-tun.exe -port=2223 into cmd, a new terminal is opened. Is it possible to continue working in the background without opening a new terminal? I already tried to do this in C++ with CreateProcess but the socket is always off here is my cpp code:

``` STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_HIDE;
ZeroMemory(&processInfo, sizeof(processInfo));
LPSTR cmdLine = const_cast<LPSTR>("-port=2223");
if (!CreateProcess("./tun.exe", cmdLine, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo))
{
    std::cerr << "Error creating process: " << GetLastError() << std::endl;
    return 1;
}
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread); ```

this code done without error but socket not working

InvisibleManVPN commented 1 year ago

Hi @hosseinkhojany! Invisible Man TUN needs administrator privilege to work properly. So, to run the service without opening a new terminal, you need to run your program as administrator. Also, can you show me how you make a socket connection between your app and tun service?

hosseinkhojany commented 1 year ago

Honestly, my program in Flutter(dart) connects to TUN socket dart await Socket.connect("127.0.0.2", 2223, sourcePort: 2223); String command = "-command=enable -device=zVPN -proxy=127.0.0.1:10801 -address=10.0.236.10 -server=${selectedVpnService .config?.vlessConfig != null ? selectedVpnService.config! .vlessConfig!.add! : selectedVpnService.config!.vmessConfig! .add} -dns=8.8.8.8"; print(selectedVpnService .config?.vlessConfig != null ? selectedVpnService.config! .vlessConfig!.add! : selectedVpnService.config!.vmessConfig! .add!); String delimiter = '<EOF>'; String message = command + delimiter; List<int> bytes = utf8.encode(message); socket?.add(bytes);

hosseinkhojany commented 1 year ago

Also I have customized the socket address to 127.0.0.2

hosseinkhojany commented 1 year ago

How to find the correct -gateway parameter ?

netsh interface ip set address name="wintun" source=static addr=192.168.123.1 mask=255.255.255.0 gateway=none

route add 0.0.0.0 mask 0.0.0.0 192.168.123.1

route add myserverip mask 255.255.255.255 ?gateway?

InvisibleManVPN commented 1 year ago

@hosseinkhojany You need to find the default gateway based on the address that you set on your wintun adapter. There are many ways to find the network's default gateway. You can write a code to find it automatically or enter the gateway manually. In Windows, you can find the default gateway automatically by using iphlpapi.dll. In Invisible Man TUN, I wrote a code to find the default gateway. See these files:

Also, see this comment: tun2socks - Proper example on Windows 10