본문 바로가기

Ops/MAC

MAC - vpn reconnect script

반응형

MAC - vpn reconnect script

 

 

 

응용프로그램 →  유틸리티 → 스크립트 편집기 실행 후 입력

 

on idle
        # Change these to your VPN's IP Address, and the VPN's name in your Mac's Network System Prefernces panel.
        set vpnIPAddress to "1.1.1.1"
        set MyVPNName to "VPN(L2TP)"
        
		# my public ip check (VPN IP)
        set myIP to "127.0.0.1"
        set shellScriptCommands to {¬
                "dig +short myip.opendns.com @resolver1.opendns.com", ¬
                "dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{ print $2}'", ¬
                "curl ifconfig.me", ¬
                "curl -s http://checkip.dyndns.org/ | grep -o \"[[:digit:].]\\+\"", ¬
                ¬ 
                        ""}
        repeat with shellScriptCommand in shellScriptComman
                try
                        set myIP to do shell script shellScriptCommand
                        exit repeat # if successful
                on error errorMessage number errorNumber
                end try
        end repeat

        # VPN IP not equal start VPN Network
        if myIP is not equal to vpnIPAddress then

                tell application "System Events"
                        tell current location of network preferences
                                set myConnection to the service MyVPNName
                                if myConnection is not null then
                                        if current configuration of myConnection is not connected then
                                                connect myConnection
                                        end if
                                end if
                        end tell
                end tell
        end if
end idle

 

이후 finder 에서 vpn_autoconnect2 더블 클릭해서 실행하고 나오는 권한 설정 해주면 됩니다.

 

 

 


by mkdir-chandler


 

 

 

 

 

728x90
반응형