Skip to content

Instantly share code, notes, and snippets.

@apietsch
Forked from 0x7An/conectar.bat
Created March 18, 2021 11:28
Show Gist options
  • Select an option

  • Save apietsch/5a1367c11cbfb50f79f0ae8c1d32ae9f to your computer and use it in GitHub Desktop.

Select an option

Save apietsch/5a1367c11cbfb50f79f0ae8c1d32ae9f to your computer and use it in GitHub Desktop.

Revisions

  1. @0x7An 0x7An revised this gist Mar 18, 2020. No changes.
  2. @0x7An 0x7An created this gist Mar 18, 2020.
    134 changes: 134 additions & 0 deletions conectar.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,134 @@
    @echo off
    echo.
    echo.
    ECHO Checking for an Internet connection, please wait...
    PING -n 1 www.google.com|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto :SUCCESS
    IF ERRORLEVEL 1 goto :TRYAGAIN

    :TRYAGAIN
    echo.
    ECHO FAILURE!
    ECHO Let me try a bit more, please wait...
    echo.
    @echo off
    PING -n 3 www.google.com|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto :SUCCESS2
    IF ERRORLEVEL 1 goto :TRYIP

    :TRYIP
    echo.
    ECHO FAILURE!
    ECHO Checking DNS...
    ECHO Lets try by IP address...
    echo.
    @echo off
    ping -n 1 8.8.8.8|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto :SUCCESSDNS
    IF ERRORLEVEL 1 goto :TRYROUTER

    :TRYROUTER
    echo.
    ECHO FAILURE!
    ECHO Lets try pinging the router....
    echo.
    ping -n 2 192.168.1.1|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto :ROUTERSUCCESS
    IF ERRORLEVEL 1 goto :NETDOWN

    :ROUTERSUCCESS
    echo.
    ECHO It appears that you can reach the router, but internet is unreachable.
    echo.
    goto :FAILURE

    :NETDOWN
    echo.
    ECHO FAILURE!
    ECHO It appears that you having network issues, the router cannot be reached.
    echo.
    goto :FAILURE

    :SUCCESSDNS
    echo.
    ECHO It appears that you are having DNS issues.
    echo.
    goto :FAILURE

    :SUCCESS
    echo.
    ECHO You have an active Internet connection
    echo.
    goto start

    :SUCCESS2
    ECHO You have an active internet connection but some packet loss was detected.
    pause
    goto start

    :FAILURE
    cls
    echo.
    echo.
    ECHO You do not have an active Internet connection
    echo Please check your WiFi Connection and try again?
    echo.
    pause
    exit

    :start
    REM Try to ping a local server inside my network
    echo Checking to see if your connected via VPN or at the Office...
    PING -n 1 192.168.168.2|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto :CHECKDEPT
    IF ERRORLEVEL 1 goto :STARTVPN

    :STARTVPN
    echo Checking to see if VPN is already loaded...
    echo.
    tasklist /FI "IMAGENAME eq openvpn-gui.exe" | find /i "openvpn-gui.exe"
    IF ERRORLEVEL 2 GOTO VPNEXIST
    IF ERRORLEVEL 1 GOTO VPNNOEXIST

    :VPNEXIST
    goto EXIT

    :VPNNOEXIST
    goto VPNNOTCONNECTED

    :EXIT

    tasklist /FI "IMAGENAME eq openvpn.exe" | find /i "openvpn.exe"
    IF ERRORLEVEL 2 GOTO VPNCONNECTED
    IF ERRORLEVEL 1 GOTO VPNNOTCONNECTED

    :VPNCONNECTED
    GOTO checkdept

    :VPNNOTCONNECTED
    taskkill /f /im openvpn.exe
    taskkill /f /im openvpn-gui.exe
    cls
    echo.
    echo.
    echo Waiting for VPN to reset...
    CHOICE /C X /T 4 /D X > NUL
    start openvpn-gui.exe --connect clockmedical.ovpn
    ECHO.
    ECHO.
    CHOICE /C X /T 2 /D X > NUL
    goto :checkdept

    :CHECKDEPT
    cls
    echo.
    echo Waiting for a solid VPN connection... Please Wait.
    PING -n 1 192.168.168.11|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto :END
    IF ERRORLEVEL 1 goto :CHECKDEPT

    :END
    REM This starts Remote Desktop called RemoteDesktop.rdp from the users profile desktop
    cd\users\%username%\desktop
    echo.
    start mstsc RemoteDesktop.rdp