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.
Related
i am making a micro-controller based dongle and i need it to interrogate host state when connected and display status (status={HOST_OFF,HOST_BOOTED,SERVICE_DOWN,SERVICE_STARTING,SERVICE_UP,SERVICE_ERROR}
i can get all the statuses from a terminal so i wanted the device to be able to login and run some commands to check stuff.
I considered the option of using CDC-ACM and a monitoring service running to update the device but that only works if the monitoring service doesn't fail (say because of disk space or port unavailable etc), and when it fails i cannot get errors.
I am basically trying to eliminate the reason for sending a tech just to look at the screen to see whats going on.
I tried just identifying device as tty device but this seems to expect a service to connect to it from the host side before i can send and characters
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 implement asynchronous download to retrieve remote file and store it in IsolatedStorage in order to use it when out of the network.
Everything works great when network is up. However when out of network, I noticed that async donwload may take up to 2 minutes before to fire my MessageBox (which say that connection to server has failed).
Question:
Is there any way to define a timeout ? Let's say that if my application does not receive any answer for X seconds then stop the Async Download and call a method.
Maybe a timeout is not the best pratices. In this case could you give me suggestion ?
I do not want my user wait for 15 seconds max.
PS: my application is suppose to run on wifi only, so I consider that 'network speed' is optimal.
Thx for your help
What I would recommend doing is check the network type first via NetworkInterface. If NetworkInterfaceType is Wireless80211, you have a wireless connection (Wi-Fi). The returned connection can be None in case there is no available way to connect - so you won't even have to start the download if there is no accessible network.
Answering your question, if you are using WebClient, you can't define a timeout. However, you can call instance.CancelAsync(). For a HttpWebRequest you can call instance.Abort().
I have a test driver program that launches a separate test server process. The test server process listens on a local port, and after it's ready, the test driver runs a test that accesses the test server.
Currently the test driver repeatedly tries to connect to the local port (loop some, sleep some, try again). It's not an optimal solution, and is clearly unreliable.
Is it possible to wait for some event that says "somebody listens on a local port"? Trying to connect to early results in a "port closed" error.
I'd like to implement the solution on Windows, Linux, and Mac OS X. If you have some tips for any of these systems, it's welcome (it's probably going to be system-specific in each case).
On Windows I use a named event for this kind of thing.
The test harness can create the event and communicate the name of the event to the server that it launches; it then waits on the event to be signalled before continuing the test. The server then connects to the event, initialises itself and once it's ready to accept connections it signals the event.
Well, if you launch the server process, you can intercept the stdout of the server right?
So have the server output "server started" when the socket ready. The driver should wait until the server sends this string to stdout, then try to connect to the server port.