JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 12.04.2020, 20:44
sanchezvictor sanchezvictor is offline
I will play nice!
 
Join Date: Apr 2020
Posts: 3
Default Windows Batch>> Reconnect VPN for windows (OpenVPN)

Hi,
let me share with you my batch process with windows. The usage is simple:
the process look inside a directory, and randomly select one of the files with "ovpn" extension.

After that, kill the OpenVPN process, and start it again connection with the file choosen.

Hope you find this useful.

EDIT by pspzockerscene:
We recommend using the current/improved versions of that script, see posts of official JD staff below.
Here you can find the version initially posted by user "sanchezvictor":

Spoiler:

Code:
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\Users\sanchezvictor\OpenVPN\config"
FOR /f %%a IN (
 'dir /b /a-d "%sourcedir%\*.ovpn"^|find /i /c ".ovpn" '
 ) DO SET /a selection=1 + (%RANDOM% %% %%a)
FOR /f "tokens=1*delims=:" %%a IN (
 'dir /b /a-d "%sourcedir%\*.ovpn"^|findstr /n /i ".ovpn" '
 ) DO IF %%a==%selection% SET filename=%%b
 
taskkill.exe /F /IM openvpn.exe
taskkill.exe /F /IM openvpn-gui.exe
timeout 1
start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --silent_connection 1 --connect %filename%

GOTO :EOF

Last edited by pspzockerscene; 24.08.2021 at 19:04.
Reply With Quote
  #2  
Old 16.04.2020, 20:07
hieunho hieunho is offline
Modem User
 
Join Date: Apr 2020
Posts: 2
Default

Can I use this right away? Or do I have to download OpenVNP and install it? Can I change the path of the config file?
Reply With Quote
  #3  
Old 19.04.2020, 20:53
sanchezvictor sanchezvictor is offline
I will play nice!
 
Join Date: Apr 2020
Posts: 3
Default

yes of course, you can change the path, and change tle VPN program for the pone you use
Reply With Quote
  #4  
Old 22.04.2020, 10:25
johnatan johnatan is offline
Modem User
 
Join Date: Apr 2020
Posts: 1
Default

As for my simple install another VPNs like Nord or Express like in this review **External links are only visible to Support Staff****External links are only visible to Support Staff**

Last edited by johnatan; 10.07.2020 at 11:00.
Reply With Quote
  #5  
Old 22.04.2020, 17:17
sanchezvictor sanchezvictor is offline
I will play nice!
 
Join Date: Apr 2020
Posts: 3
Default

first of all, if you are using OpenVPN, you can use NordVPN too. OpenVPN is just an open source client to connect with your VPN provider.

sencond, it doest matter what VPN provider you are using.You have to restart and select another Server because you need that your IP changes (otherwise you cannot continue downloading from mega or another file servers). It is the same as restart your router to get the IP changed.

This script is usefull for that purpouse: in case you have a private VPN provider (no matter which one) and in case you are usen OpenVPN as a client, you could have a directory in your PC with the "ovpn" files (the files you need to connect to one or another server) and randomly this script choose one to connect.
Reply With Quote
  #6  
Old 12.06.2021, 01:53
zr0cool zr0cool is offline
Modem User
 
Join Date: Jun 2021
Posts: 2
Default

Sorry to resurrect an old thread but wondering if anyone can help with this script.

When I try running this, I get an error saying 'cannot find requested config to autostart: %filename%'

Am I missing something? I changed the sourcedir to match the correct location.
Is there something else I need to be changing?

Thanks!
Reply With Quote
  #7  
Old 15.06.2021, 12:37
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 72,936
Default

Can you please share your script? screenshot?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #8  
Old 24.06.2021, 06:33
zr0cool zr0cool is offline
Modem User
 
Join Date: Jun 2021
Posts: 2
Default

Code:
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\Program Files\OpenVPN\config"
FOR /f %%a IN (
 'dir /b /a-d "%sourcedir%\*.ovpn"^|find /i /c ".ovpn" '
 ) DO SET /a selection=1 + (%RANDOM% %% %%a)
FOR /f "tokens=1*delims=:" %%a IN (
 'dir /b /a-d "%sourcedir%\*.ovpn"^|findstr /n /i ".ovpn" '
 ) DO IF %%a==%selection% SET filename=%%b
 
taskkill.exe /F /IM openvpn.exe
taskkill.exe /F /IM openvpn-gui.exe
timeout 1
start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --silent_connection 1 --connect %filename%

GOTO :EOF
Reply With Quote
  #9  
Old 25.06.2021, 16:25
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 72,936
Default

@zr0cool: Are the paths all okay? your configs in correct folder?
what happens you start the scrip in cmd.exe ?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #10  
Old 04.08.2021, 06:41
teosanru teosanru is offline
I will play nice!
 
Join Date: Aug 2021
Posts: 2
Default

Hello, I found this thread in the forum, and I would like to know how to make jdownloader wait until openvpn reconnects with this script, because there is always traffic leakage. is there any way to tell jdownloader to always use openvpn's network adapter or network and not my ISP's. I also have another question. I tried to use this script directly in jdownloader in the section on external reconnection in batches, but it threw me an error. so I had to create an external .bat file and use it with reconnection with external tools but I read in another section that when the script is not used directly in the external tool in jdownloader batches, then jdownloader will not know that a reconnection is being executed
Reply With Quote
  #11  
Old 19.08.2021, 02:06
joelli joelli is offline
Linkgrabbing Monster
 
Join Date: Mar 2009
Posts: 83
Default

same here, cmd:

C:\>@ECHO OFF
SETLOCAL
SET "sourcedir=C:\Program Files\OpenVPN\config"
FOR /f %%a IN (
"%%a" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
'dir /b /a-d "%sourcedir%\*.ovpn"^|find /i /c ".ovpn" '
Der Befehl "'dir" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
) DO SET /a selection=1 + (%RANDOM% %% %%a)
FOR /f "tokens=1*delims=:" %%a IN (
"%%a" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
'dir /b /a-d "%sourcedir%\*.ovpn"^|findstr /n /i ".ovpn" '
Der Befehl "'dir" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
) DO IF %%a==%selection% SET filename=%%b

taskkill.exe /F /IM openvpn.exe
FEHLER: Der Prozess "openvpn.exe" wurde nicht gefunden.
taskkill.exe /F /IM openvpn-gui.exe
FEHLER: Der Prozess "openvpn-gui.exe" wurde nicht gefunden.
Reply With Quote
  #12  
Old 20.08.2021, 11:56
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 72,936
Default

@teosanru: yes, you have to setup Settings->Connections and there you can setup direct and enter the network device name of your vpn adapter, and either disable "no proxy" or change it to whitelist only for jdownloader.org and appwork.org, that way JDownloader can still update/be reachable via MyJDownloader even if vpn is broken/down. You can use board search for this
When you already have a working batchfile/tool, then just setup that in Settings->Reconnect
__________________
JD-Dev & Server-Admin
Reply With Quote
  #13  
Old 20.08.2021, 11:57
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 72,936
Default

@joelli: can you please explain your problem?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #14  
Old 23.08.2021, 20:50
joelli joelli is offline
Linkgrabbing Monster
 
Join Date: Mar 2009
Posts: 83
Default

Quote:
Originally Posted by Jiaz View Post
@zr0cool: Are the paths all okay? your configs in correct folder?
what happens you start the scrip in cmd.exe ?
Quote:
Originally Posted by Jiaz View Post
@joelli: can you please explain your problem?
Have the same script tested, but does not work for me either. The submitted log is from cmd.

"taskkill.exe /F /IM openvpn.exe
FEHLER: Der Prozess "openvpn.exe" wurde nicht gefunden.
taskkill.exe /F /IM openvpn-gui.exe
FEHLER: Der Prozess "openvpn-gui.exe" wurde nicht gefunden."

this output seems wrong, openvpn.exe and openvpn-gui.exe are killed! I have to start them manually again.

Last edited by joelli; 23.08.2021 at 21:09.
Reply With Quote
  #15  
Old 23.08.2021, 21:06
pspzockerscene's Avatar
pspzockerscene pspzockerscene is online now
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 59,736
Default

I've found one possibly fatal mistake in this CMD script:
Code:
start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --silent_connection 1 --connect %filename%
"%filename%" will contain the filename of the config file.
If that contains bad chars such as spaces or "-" this may lead to issues so you need to wrap it in quotation marks.
A lot of users might use the "premiumize.me" OpenVPN config files.
Their (new) default premiumize.me config files filenames e.g. contain spaces and a "-" which will result in a failure when being used with the first version of the above CMD script.

I've made some minor changes and this one worked fine for me:
Click on "Spoiler: show" to view the batch script!
Spoiler:

Code:
@ECHO OFF
SETLOCAL
SET "openvpndir=C:\Program Files\OpenVPN"
SET "openvpndir_config=%openvpndir%\config"
SET "openvpndir_bin=%openvpndir%\bin\openvpn-gui.exe"

REM TODO: Write a file in order to be able to know the last used config -> Avoid connecting to the same one as before again thus wasting time!
FOR /f %%a IN (
 'dir /b /a-d "%openvpndir_config%\*.ovpn"^|find /i /c ".ovpn" '
 ) DO SET /a selection=1 + (%RANDOM% %% %%a)
FOR /f "tokens=1*delims=:" %%a IN (
 'dir /b /a-d "%openvpndir_config%\*.ovpn"^|findstr /n /i ".ovpn" '
 ) DO IF %%a==%selection% SET filename=%%b


REM exit OpenVPN if it's running
echo Killing OpenVPN
REM TODO: Do not display errors in console for this one
taskkill.exe /F /IM openvpn.exe
echo Re-opening OpenVPN
REM TODO: Do not display errors in console for this one
taskkill.exe /F /IM openvpn-gui.exe
echo Sleep after kill
ping localhost -n 5>nul

echo connecting to VPN config: %filename%
start /b "" "%openvpndir_bin%" --silent_connection 1 --connect "%filename%"
REM If we don't do this JD might detect our non proxy VPN as new IP which would be wrong!
echo Sleep some seconds before batch exit
ping localhost -n 10>nul
GOTO :EOF


-psp-
__________________
JD Supporter, Plugin Dev. & Community Manager
JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
That's true James
Quote:
Originally Posted by James
Die Leute verstehen einfach nicht dass nur weil man mit einer Waffe auch auf Menschen schießen kann dass ein Schützenver​ein kein Ort für Amoklaufide​en ist

Last edited by pspzockerscene; 24.08.2021 at 18:57.
Reply With Quote
  #16  
Old 24.08.2021, 00:11
joelli joelli is offline
Linkgrabbing Monster
 
Join Date: Mar 2009
Posts: 83
Default

tested this one with the "test" button in JD.

Result: %openvpndir_bin% konnte nicht gefunden werden...

Openvpn in at my PC: C:\Program Files\OpenVPN\bin

anything wrong?


In JD is the option: Starte in
I wrote this into the line: C:\Program Files\OpenVPN\bin
does this have any influence?

Last edited by joelli; 24.08.2021 at 00:20.
Reply With Quote
  #17  
Old 24.08.2021, 19:02
pspzockerscene's Avatar
pspzockerscene pspzockerscene is online now
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 59,736
Default

I've added some more enhancements to that script and I'll add some more the next few days or next week along with a help article just for using OpenVPN to reconnect (under Windows).

Until then, here is a short answer:
1. Use all of the above script code, paste it into a text-editor of your choice and save it as "openvpnreconnect.bat" (do NOT save it as TXT file/.txt extension!).

2. Now open JD -> Settings -> Reconnect -> Batch Script and enter the path to your batch file e.g.:
Code:
C:\Users\yourUsername\Downloads\openvpnreconnect.bat
3. Click the "Test" button.
After 10-15 seconds, you should see "Reconnect successful".

As said I will add better instructions and update the script as there is still plenty of room for improvements

-psp-
__________________
JD Supporter, Plugin Dev. & Community Manager
JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
That's true James
Quote:
Originally Posted by James
Die Leute verstehen einfach nicht dass nur weil man mit einer Waffe auch auf Menschen schießen kann dass ein Schützenver​ein kein Ort für Amoklaufide​en ist
Reply With Quote
  #18  
Old 24.08.2021, 19:32
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 72,936
Default

@joelli: we also found a possible bug that could cause JDownloader to wait longer than required for script and thus fail to recognize the changed IP. this will be fixed with core update
__________________
JD-Dev & Server-Admin
Reply With Quote
  #19  
Old 24.08.2021, 20:14
joelli joelli is offline
Linkgrabbing Monster
 
Join Date: Mar 2009
Posts: 83
Default

Quote:
Originally Posted by pspzockerscene View Post
2. Now open JD -> Settings -> Reconnect -> Batch Script and enter the path to your batch file e.g.:
Code:
C:\Users\yourUsername\Downloads\openvpnreconnect.bat
3. Click the "Test" button.
After 10-15 seconds, you should see "Reconnect successful".

-psp-
I am right with "Drittanwender Reconnect" as Batch script?

This comes up, when i try with "Test" Button:
"kann gewünschte Konfigurationsdatei für Autostart nicht finden"

Openvpn is killed after the "Test"
Reply With Quote
  #20  
Old 25.08.2021, 12:46
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 72,936
Default

@joelli wir können auch gerne in Deutsch schreiben
__________________
JD-Dev & Server-Admin
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 20:42.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.