S
S
Sergey Ponomarenko2015-08-06 15:24:48
cmd/bat
Sergey Ponomarenko, 2015-08-06 15:24:48

Is it possible to create one .bat file for connecting and disconnecting to the internet?

I found this .bat file to connect:

cd %systemroot%\system32 
start rasdial [имя_подключения] [имя_пользователя] [пароль]

and this one to disable:
cd %systemroot%\system32 
start rasdial [имя_подключения] /disconnect

I need one file! - or a simple .bat or other script that would check if there is an Internet connection, and if so, then turn it off, and if not, then connect it.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2015-08-06
@darkonus

Given the idea of ​​GavriKos :

ping -n 2 8.8.8.8|Find /I "TTL="||goto no_inet

cd %systemroot%\system32 
start rasdial [имя_подключения] /disconnect
goto end

:no_inet
cd %systemroot%\system32 
start rasdial [имя_подключения] [имя_пользователя] [пароль]

:end

G
GavriKos, 2015-08-06
@GavriKos

Python is in your hands. Ping 8.8.8.8, and depending on the availability, choose what to do. You can directly rasdial from Python and call it, if that.

E
Eugene, 2015-08-06
@yellowmew

powershell script, but will run from a bat file if you have Windows 8 and higher
If the OS is lower than Windows 8, then here is the contents of the batch file:

ping хост -n 1 > %TEMP%\ping1.txt
if %errorlevel%==1 (rasdial название_ВПН_соединения логин пароль) else (rasdial название_ВПН_соединения /disconnect)

In the second case, you need to choose the right host to ping:
If you have an Internet connection like this, then it must be a public host from the Internet (for example 8.8.8.8 ). If you connect to a working network in this way, then the host must be from a working network (inaccessible without an established connection).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question