There doesn't seem to be any easy way to tell Windows 7 that a network connection should allways use a VPN connection (like it is in Linux), so I've been playing around a bit with Task Scheduler to do this.
What I need is to automatically connect to a VPN when a WLAN connection is established. Why? Because if I connect to the VPN manually, every time I put the computer to sleep or hibernate it, the VPN is disconnected and I have to connect manually again. Which is easy to forget.
In Task Scheduler, I've created the following:
Triggers:
On an event -> Log: System, Source: Power-Troubleshooter, Event ID: 1
On an event -> Log: System, Source: Kernel-Power, Event ID: 42
(I found the above in a tutorial, and they seem to work.)
Action: rasdial
This works. When running the task manually, it connects to the VPN.
However, the problem is that when logging in after sleep/hibernation, the task is run immediately. Hence, it runs before the WLAN connection is established, thus failing and quitting in a couple of seconds.
So, what I need is to delay the task for a few seconds, until the WLAN connection is established. Either for a specified number of seconds, or better - wait for the WLAN connection to be established.
Is there any way of doing this, without creating a script file with a wait function? The task can be set to retry if it fails, but only with 1 minute intervals, which is much too long.
If the only solution is to create a script file for starting the VPN connection, and adding a wait function there, could someone show me an example? (I'm not good at windows scripting at all.)
I don't think there's a way to do that without scripting it. At least not that I know of (which doesn't necessarily mean very much).
If you want to script it, here's a simple .vbs script that waits before running the rasdial command:
WScript.Sleep 5000
Set objShell = "WScript.CreateObject("WScript.Shell")
objShell.Run """c:\windows\system32\rasdial.exe"" <vpn connection> <username> <password>", 1, True
Set objShell = Nothing
Then just run this script file instead of the rasdial.exe command from the Task Scheduler.
Related
My college requires students to periodically authenticate for using WiFi and LAN. I am writing a Python script that will automatically do that so that I don't have to manually enter my credentials. The authentication is also separate for WiFi and LAN, and that makes me enter my credentials when I switch between them. So, for the python script, I want to detect when my authentication has expired and my connection is disconnected.
I also don't want the python script to be running constantly in the background and pinging a website as that really isn't optimal and I'll have to run the script every time my PC restarts. I was thinking of using the Windows Task Scheduler to fire the script when it detects that my connection is lost. The trigger event cannot be fixed intervals as the connection can be lost in between the intervals and also when switching between LAN and WiFi.
So, is there any network event that will capture the functionality I want? As Windows gives a notification of "opening the browser to connect" I feel there has to be a background event running.
I tried the NetworkProfile/Operational Event in the Task Scheduler with event id 10001 and 8003. But that just fires when I switch off the WiFi of my PC.
Thank you
Got it!
NetworkProfile/Operational Event with ID 4002 waits for network authentication.
If I start an SSH connection with my windows 10 laptop, it gets aborted within a minute. Even when I'm actively using the connection.
I tried multiple servers (Ubuntu 18, 16 and ESXi 6.7) all with the same problem, also tried to use different clients (putty and mobaXterm).
Did a packet capture and it does look like the connected server sends a RST with ACK to my laptop. After which my laptop responds FIN with ACK.
If I setup the same connection from my phone with JuiceSSH it keeps working normally. That's why I suspect my laptop, but I have no idea how to resolve it.
Any ideas?
In putty feel free to try with:
In your session properties, go to Connection and under Sending of null packets
to keep session active, set Seconds between keepalives (0 to turn off) to e.g.
300 (5 minutes).
source: https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/
I have a script written in VBS that checks every second if the LAN port has a connection and if so, disables the wireless, or enables the wireless if no LAN connection exists. There's an unfortunate bug in this that leaves the wireless disabled if you shut down the computer while this script is running that I would like to fix. The script runs at logon via a GPO, so it won't run if one logs in off the network.
Is it at all possible to catch the End Task signal and perform cleanup operations before the script ends? I'd like for this to re-enable the wireless as the system shuts down.
Thanks
No i think it is not possible and if so it would be unreliable or slow down your pc i'm afraid. But just as you can have a script running at logon you can also have a script running at logoff, i suggest you take that road.
I'm working with an embedded system which has a RAS entry already set up, using the API function RasDial from rasapi32.dll.
All works well except if something goes wrong after RasDial and before RasHangUp. In this case any further attempt to dial is met with error 756 "connection is being dialled", whether the dial attempt is done via the API or via the Windows rasdial command line utility.
rasdial connectionname /d doesn't help either.
The com port used for the modem is locked.
The only way to recover is to reboot.
Obviously under normal circumstances the solution is to make sure that RasDial is always followed by RasHangUp. But for cases where this doesn't happen, is there a way of aborting the dial attempt? For example, if the app calls RasDial and then crashes, how do I get out of that other than by rebooting?
Unfortunately, unless your application can properly terminate the connection that's in progress before exiting the RAS state machine becomes corrupted and must reboot to fix the problem. I've noticed that Windows 7 handles these sorts of scenarios better than XP and Vista did, but there are still occasions when I've had to reboot.
I've managed to prevent most of these sorts of problems with the DotRas API as long as they're occuring in the event handlers of the RasDialer, but if the application crashes from another thread and not from the background thread which raises the RasDialer events, there's nothing I can do about that.
For asynchronous dialing using the DotRas 1.2 SDK:
using DotRas;
RasDialer dialer = new RasDialer();
dialer.EntryName = "My Connection";
dialer.Credentials = new NetworkCredential("My", "User");
dialer.DialAsync();
From this point you can call dialer.DialAsyncCancel() if you want to cancel the connection attempt that's in progress.
For synchronous dialing using the DotRas 1.2 SDK is very similar to asynchronous dialing other than replacing the DialAsync call with simply dialer.Dial().
Here's a link to the API I was talking about: http://www.codeplex.com/DotRas
Hope that helps!
I need to have as quick timeout as I get (connection failed) on windows. but on solaris its much longer, how can I make it shorten? (I'm trying to connect on purpose to a machine that does not exist to simulate a machine is down).
When I'm performing this on windows --> timeout --> good
D:>telnet 192.168.23.21 222
Connecting To 192.168.23.21...Could not open connection to the host, on port 23:
Connect failed
D:>
on windows (the target ip does not exist)
then in about 15 seconds the command terminates.
However when I perform this from a solaris --> very long timeout --> not good for my legacy code machine like this:
myuser#mycomp:~$ telnet 192.168.23.21 222
Trying 192.168.23.21...
Then the process does not terminate
and this has major implications for me because i'm migrating an app from windows to solaris, and I must be able to have this timeout (in legacy code which I cannot update), so I need at the OS level to control this timeout to be as short as is currently in windows. How can I change this timeout in my solaris OS then? to be short, just as I havbe it on windows
Thanks
If you absolutely have to do this systemwide, there's a TCP driver parameter tcp_ip_abort_cinterval that can be modified:
tcp_ip_abort_cinterval - This is the
amount of time that a connection is
allowed to stay in a half open state. This is 180,000
(3 minutes) by default. You can change this to 25,000
if you want (25 seconds). Please note that by changing this
you may find that SLIP/PPP users may have problems conacting
your site.
To view your current setting:
/usr/sbin/ndd /dev/tcp
tcp_ip_abort_cinterval
To change the setting:
/usr/sbin/ndd -set /dev/tcp
tcp_ip_abort_cinterval 25000
Perhaps you could set the socket option SO_SNDTIMEO -- that link reports Solaris doesn't respect that option, but you might be lucky and they've fixed it by now. :)
If the socket option doesn't work, you could always set an alarm(2) for some point in the future and interrupt your connect(2) call. It feels pretty gross, but it is an option.
Another option is to switch to non-blocking socket operations and poll at some point in the future if the connect(2) operation succeeded or not. You could see a timeout to select(2) and discover if it has errored or is readable/writable. (See also the EINPROGRESS bit in connect(2).)