Applescript to Automatically Connect VPN
Recently got a MacBook and when I'm at home I use it to connect to my university's VPN connection. This works well except for the fact that it disconnects every time my laptop sleeps or locks so I wrote this applescript:
on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "VPN University"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
return 120
end tell
end idle
I also edited the info.plist so that the application was completely hidden at all times. This works well whilst I have the ethernet cable attached and want to be on the VPN, but as soon as I move away from my desk I want to be on the wifi and the continuous 'failed to join VPN' error messages are quite annoying.
I was wondering if there was an applescript workaround that would somehow test whether I have the ethernet cable attached? I realise I may be asking a bit much.
Thanks.
I think you just need to wrap your whole script in a test to see whether ethernet is connected:
on idle
set ethernet to do shell script "ipconfig getifaddr en0; exit 0"
if ethernet is not "" then
tell application "System Events"
tell current location of network preferences
set myConnection to the service "VPN University"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
return 120
end tell
end if
end idle
Similar Messages
-
Applescript/Ping/Connect VPN
I wrote an Applescript to start the VPN and then mount a network drive. Now I would like to add logic to the beginning to ping an internal resource first. If the resource is unreachable, then connect and mount the drives. Otherwise, just mount the drives.
Basically, I obviously don't need the VPN if the machine is on the network. I would then just need to mount the dirves. But if it's not on the network, I would need to connect to the VPN first.
My plan is to save it as an app and have it run at logon.
Here is what I have so far. Any help would be appreciated.
tell application "System Events"
tell current location of network preferences
set VPNservice to service "AWH VPN"
connect VPNservice
end tell
end tell
delay 10
try
mount volume "smb://Drive/share"
end tryThis doesn't seem hard to me...
I would like to add logic to the beginning to ping an internal resource first.
You can just have your script ping the server address first and connect the VPN if you're unable to, like:
try
do shell script "ping -c 1 -t 1 hostname.of.your.server"
on error
-- we're not online, so connect the VPN
tell application "System Events"
tell current location of network preferences
set VPNservice to service "AWH VPN"
connect VPNservice
end tell
end tell
delay 10
end try
try
mount volume "smb://Drive/share"
end try
The premise here is that the 'do shell script "ping..."' will fail if the server can't be reached, thereby triggering the 'on error' part of the script (where you establish the VPN connection).
If the server can be reached then the 'on error' code is skipped, leading to the part of the script that mounts the share point. -
My iPhone 5 will not automatically connect to my home wifi
My wifes iPhone 5 will not automatically connect to our home wifi, she has to log in each time (she has ios 6.1.4). Mine, however will connect automatically with no issues (we have same phone and ios). Here is what I have done so far to fix the issue and none have worked:
* I have reboted (hold home button and sleep/wake button)
* I have reset the network connections
* I have turned "ask to join" on, connected to the network, turned wifi off and then back on, it did not connect to the wifi
* I have manually connected to the network through the manual option, turned wifi off and then back on, it did not connect to the wifi
* I have erased all content and data and resored the backup from iTunes
* I have restored iPhone from iTunes and restored the backup from iTunes
My phone does not list a "forget this network" as an option on the wifi connection when I pull it up, so this is not an option. So, what else is there to fix the issue?Hi there Huskerscott!
I have some information here that can help you troubleshoot this issue:
Unable to automatically connect to Wi-Fi
Avoid giving your Wi-Fi network a common name.
Some wireless routers are preconfigured with a common SSID (network name) such as "wireless" or "default."
If your desired Wi-Fi network has a common SSID, try changing the SSID to something unique2.
If your desired Wi-Fi network has a unique SSID, reset network settings by tapping Settings > General > Reset > Reset Network Settings.
Note: This will reset all network settings including: previously connected Wi-Fi networks and passwords, recently used Bluetooth accessories, VPN and APN settings.
Which is taken from this article:
iOS: Troubleshooting Wi-Fi networks and connections
http://support.apple.com/kb/ts1398
It also may be helpful to follow these settings, which are optimal for use with iOS and OS X devices:
iOS and OS X: Recommended settings for Wi-Fi routers and access points
http://support.apple.com/kb/ht4199
Thanks for being a part of the Apple Support Communities!
Regards,
Braden -
Terminal Commands for Internet Connect VPN?
I could maybe do this as an applescript but I'm hoping there are terminal commands which I can incorporate into an rsync script...
I need to open a PPTP VPN connection on a computer (Internet Connect VPN client, 10.4.8) , to connect to VPN services on OS X Server (10.4.8). The configuration works fine but really needs manual intervention at times. I would like to just script the equivalent of hitting the 'connect' button, so this can be run by cron.
Any ideas or links?
Ta.
-davidI did repair permissions with disk Utility and I used Onyx to delete the various caches, but that didn't work.
Everything is functioning. The problem isn't on the VPN server side, because I can log into the VPN on my Powerbook and the status shows correctly. There's definitely something going on with my G5.
This isn't a really huge deal, but it would be nice if the status indicated that I'm connected when I'm connected. -
Proper way to Connect to Automatically Connect to SSH Server
What is the proper way to automatically connect to an ssh server via applescript?
I've tried a variety of different things, none of them seemed to have worked yet... I've searched Google for quite awhile, and was wondering if anyone could please shed some light.
1. do shell script "ssh user@hostname"
Error Msg: Pseudo-terminal will not be allocated because stdin in not a terminal
2. do shell script "ssh -t -t user@hostname"
Error Msg: None; However it doesn't allow me to put a password in
3. do shell script "ssh user@hostname > /dev/null &"
Error Msg: None; Same as above
4. tell application "Terminal"
do script "stty -echo"
do script "ssh user@hostname"
end tell
Error Msg: None. Popups a terminal window for user to enter password
I've been using password prompt box, for the user to enter a password and would like a way to pass it directly to ssh terminal running in the background.
I've also though about using SSH RSA keypairs the only way to accomplish this (no login regquired) but would prefer to use user/password authentication rather than trusted RSA keypairs.I am trying to setup an automated port forward through ssh -L and run it in the background for someone who has no idea what ssh is..
Then either Terminal.app or private keys are your option.
Could you shed some light on why RSA private keys are more secure? Because can't they be used by any user on that machine?
Not unless you set it up wrong.
SSH keys require two matching pieces of information - a private key (normally stored in the .ssh directory in your home directory) and a matching public key stored in the authorized_keys file in the .ssh directory of the home directory of the account you're logging in as.
These two pieces of data have to match and since they're in the home directories of the respective accounts, they are only accessible to the specific user and not everyone.
Whereas password authentication requires it to typed in.
And if it's wrong (e.g. a hacker guesses incorrectly) he can try again, and again, and again until he either gets bored (not likely since he's probably using an automated script anyway) or he gets lucky and gets in.
People are notoriously bad at selecting passwords. All too often passwords are weak and can be broken via simple dictionary attacks (try combinations of common dictionary words) or social engineering techniques. Public keys cannot be broken in such way (or, at least, the brute force attack is estimated to take the average hacker several years to break through).
There are also trojan keylogger applications (more common on Windows, of course) - these have the ability to record every keystroke made on the system, which makes it easy to capture someone's password any time they type it. -
Create an applescript to automate PDF compare?
I need to create an applescript to automate comparing B4 and After PDF. Can this be done with applescripting.
I know of no way to automate it. The PDF that you see really only exists on the screen. The internal structures that define it have little or no connection to the display. For example, if you open a Word document in a basic text editor, in between the special characters you can still read the text. You can't do that with a PDF. A PDF that appears to be entirely text may not contain any text.
You would have to develop a system that exported text and compared the text. Such a system would fail more often than not. You could instead create a system that exported each PDF as an image and compared the image. You would likely get false positives but it should work.
Adobe claims to have a diff feature in Acrobat Pro: http://www.adobe.com/ca/products/acrobat/file-compare-two-pdf-files.html
There are some open-source tools as well: http://www.qtrac.eu/diffpdf.html
Good luck with either.
If you are the one making the changes, you could use Preview's browse versions feature to visually compare them. -
Not automatically connecting to known Wifi networks anymore.
A few days ago my Macbook prompted me to update, i didn't check to see what the update was, but regardless since then my macbook refuses to automatically connect to known networks when i login/wakefromsleep etc. This is not just at home, even at my University it's having trouble connecting to the secure network there (which it used to connect to with no issue) and I'm being forced to use the open network with a VPN app. Is anyone else suffering a painfull airport? Any suggestions? Any way to undo the latest update if that is infact the cause?
Thanks.
John
Message was edited by: johnazI have had wireless problems intermittently for a year, and seriously for 6 weeks. Apple denied the issue and was no help in spite of many tens of thousands of people on their own discussions complaining. I found a post suggesting a couple of things which fixed the problem. I don't know if both are necessary, but the first by itself does not solve the problem.
Lock the channel of your router to channel 1, apparently Apple and 802.11n don't play well together on higher channels. When this becomes a standard this will be resolved I hope.
Open your network preferences, select 'airport' and advanced. Delete unused networks. Select your network.
Open TCP/IP and write down all the settings, configure iPv4 manually. Enter the settings manually. Turn off IpV6.
Open DNS and write down your DNS server. Delete it and re-enter it manually.
This has worked on 2 macbooks and an iMac for the last 3 weeks with no network drops.
Joe Shea
Philadelphia -
Email no longer automatically connects
Probably when I upgraded to 3.0, my original iPhone (and my wife's) stopped automatically connecting to email, both POP and IMAP. I have to launch the email application on my phone before it will connect and show new messages in the queue. I'm assuming that this is the price of running 3.1 on my tired old phone. Anybody else having this problem? Any suggestions?
In the signature preferences make sure that, for each account, you have selected a signature at the "choose signature" popup.
AK -
ASA Remote Access VPN: internal LAN cannot connect to connected VPN clients
Hi community,
I configured IPSec remote Access VPN in ASA, and remote client use Cisco VPN client to connect to the HQ. The VPN is working now, VPN clients can connect to Servers inside and IT's subnet, but from my PC or Servers inside LAN cannot ping or initial a RDP to connected VPN clients. Below is my configuration:
object-group network RemoteVPN_LocalNet
network-object 172.29.168.0 255.255.255.0
network-object 172.29.169.0 255.255.255.0
network-object 172.29.173.0 255.255.255.128
network-object 172.29.172.0 255.255.255.0
access-list Split_Tunnel remark The Corporation network behind ASA
access-list Split_Tunnel extended permit ip object-group RemoteVPN_LocalNet 10.88.61.0 255.255.255.0
ip local pool remotevpnpool 10.88.61.10-10.88.61.15 mask 255.255.255.0
nat (inside,outside) source static Allow_Go_Internet Allow_Go_Internet destination static remotevpnpool remotevpnpool
crypto ipsec ikev1 transform-set myset esp-aes esp-sha-hmac
crypto dynamic-map dyn1 1 set ikev1 transform-set myset
crypto map mymap 65000 ipsec-isakmp dynamic dyn1
crypto map mymap interface outside
tunnel-group remotevpngroup type remote-access
tunnel-group remotevpngroup general-attributes
address-pool remotevpnpool
authentication-server-group MS_LDAP LOCAL
default-group-policy Split_Tunnel_Policy
I don't know what I miss in order to have internal LANs initial connection to connected vpn clients. Please guide me.
Thanks in advanced.Hi tranminhc,
Step 1: Create an object.
object network vpn_clients
subnet 10.88.61.0 mask 255.255.255.0
Step 2: Create a standard ACL.
access-list my-split standard permit ip object RemoteVPN_LocalNet
Step 3: Remove this line, because I am not sure what "Allow_Go_Internet" included for nat-exemption.
no nat (inside,outside) source static Allow_Go_Internet Allow_Go_Internet destination static remotevpnpool remotevpnpool
Step 4: Create new nat exemption.
nat (inside,outside) source static RemoteVPN_LocalNet RemoteVPN_LocalNet destination static vpn_clients vpn_clients
Step 5: Apply ACL on the tunnel.
group-policy Split_Tunnel_Policy attributes
split-tunnel-policy tunnelspecified
split-tunnel-network-list value my-split
Step 6:
I assume you have a default route on your inside L3 switch point back to ASA's inside address. If you don't have one.
Please add a default or add static route as shown below.
route 10.88.61.0 mask 255.255.255.0 xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx = equal to ASA's inside interface address.
Hope this helps.
Thanks
Rizwan Rafeek -
I'm new to macs as of last night. Which would explain why perhaps this is an easy task, but I have difficulty with it. Here's my situation; my wireless network is password protected. When I initially connected to it it prompted me to put in a password, I did, and then I was connected. Every time I turn my computer back on or wake it up, I have to go up, click on wifi, click on "Tardis1" and click connect. It doesn't ask me to put in the password again, however it doesn't connect automatically like it should. It also gives me this message every time I manually link it, "Mac connected as wep but not wepa/wepa2 personal" or something along those lines. Any help would be great, thanks!
Hello, andyBall_uk. I figured out the problem, and I'm going to reply to it on here in case anybody else has the same issue they can see this solution. I already had an iOS device before, which saved a "keychain" of the old login info for the router. This was back when the router did have WEP security. Since then, it has been reconfigured for WPA2 however my old keychain was trying to join it as WEP.
To solve this, I went to System Preferences>Network>Advanced
From here, I noticed the
[ + ] [ - ] Drag Networks into the order you prefer
Highlighting my router and hitting the [ - ] sign removed the keychain that would previously only connect as WEP. This now allowed my computer to automatically connect to the router every time I opened it or turned it on. -
hi, how do i stop my macbook pro not to automatically connect to a wifi connection that is not my preferred network? i want to automatically connect my macbook to my preferred network everytime i turn on my laptop. thank you.
System Preferences > Network > WiFi
To give a network the highest priority, drag the name of the network to the top of the list. This is the network your computer will attempt to join first.
http://support.apple.com/kb/PH13797 -
Macbook Pro keeps saying connection timeout and it used to connect to the internet fine. What's up, why can't it find and automatically connect to the internet anymore???
Like this: https://discussions.apple.com/thread/2775868?tstart=0 ?
-
How come my macbook Pro doesn't automatically connect to my wifi when it is saved under known networks and i have the box checked under network settings?
Random35,
does your wi-fi router filter access by MAC address? If it does, then have you added your MacBook Pro’s MAC address to your router’s whitelist of acceptable MAC addresses? -
Macbook pro doesn't automatically connect to my wireless network
I have set up my network preferences with my wireless networka the top of the list. This used to ensure I automatically connected, but now I have to manually connect everytime I wake my computer.
Some possible fixes can be found here:
https://discussions.apple.com/thread/3194917
charlie -
MacBook Pro won't automatically connect to my Time Capsule for WiFi
My 2012 MacBook Pro (non-retina) won't automatically connect to my Time Capsule for WiFi. I had issues with my Comcast router before, and i reset my time capusle a few times, is that th reason why now everytime i wake my macbook up it dosent automtically connect?
Yes.. wireless after sleep or reboot is a problem. See the info from Tesserax.
https://discussions.apple.com/community/wireless/airport?view=documents
Unable to connect after sleep .. you will see it in the list.
Maybe you are looking for
-
Java Web Start running JasperReports
The following is the exception that is thrown when trying to compile an .xml report template to a JasperReport object, from an app that has been deployed via the Java Web Start: dori.jasper.engine.JRException: Errors were encountered when compiling r
-
Determine if a number is even or odd in php
hi, working on a site that uses php and mysql. on one page, i pull data from a database and put it into a table. the data is about scientific papers so i have the following fields: id (unique to each row), title, author, type, content (contains url t
-
Uploading XML file to SharePoint Online Document Library
Hi, I got a scenario to upload the xml file the sharepoint library along with that the XML has some information like UserName, Email. Phone and these information has to be captured to the metadata information of that file in the sharepoint library. L
-
Cisco ise Repository not found
I have a standalone ISE node, which is being stubborn about an upgrade... The docs say this should work, but I'm getting an error... ISE-01/admin# application upgrade ise-upgradebundle-1.1.x-to-1.2.0.899.i386.tar.gz disk Save the current ADE-OS runni
-
I would like to bring in movies or projects from LT that have transparent text ("alpha" layer?) and a solid background. The goal is to layer fcp video under the animated text generated in LT so that the video layer fills the transparent text layer. I