A batch file to check internet connection and shutdown pc, if offline - batch-file

The title pretty much says it all. So, I have a no-break connected to my PC, because we have a lot of blackouts here where I live. The problem is: if I'm not at home, who will shutdown my PC correctly if there is a blackout? So, I realized that my modem is not connected to the no-break; this means that, in the case of a black-out, my modem will turn off, thus, no internet will reach my computer, so this is kind of a way to tell my PC when lights are out.
Sure, this might not be always the case (sometimes the internet just goes off for reasons other than power), but I will accept this risk.
So, what I am looking for is a code that, once I execute it (what I'll do when I'm leaving home), checks if there is internet conection. If yes, than do nothing and keep checking. If not, than shutdown the computer.

Related

ipmi-console: SOL connection idle on dell servers

I'm working with server automation tools on some Dell C2100 and C1100 servers. What I intend to do is connecting via Serial Over Lan using ipmi.
A few weeks ago, I was able to connect to one of my servers using ipmi-console (from freeipmi), like this:
ipmi-console -h IPADDRESS -u USER -P
This started up a SOL connection, and this way I was able to automate some interactions with the server's BIOS settings and other stuff.
However, a few days later, the same script didn't work anymore. It just says "[SOL established]", and that's it: the SOL connection never shows any feedback, and it stays idle until I close the connection.
My question is: what could possibly have changed that the SOL connection is not working anymore.
I obviously checked for anything related to SOL and IPMI, both in BIOS settings and using BMC web GUI. But everything looks normal, and I didn't recall to have changed anything there between the time the connections worked and then they stopped working. IDK what else to check, and it just fails w/o errors anywhere.
Perhaps this is a common thing with IPMI and/or SOL, but I frankly don't understand it. So, any pointer would be nice.
Thanks in advance.
FreeIPMI maintainer here. When no data is being output, it is typically a configuration problem. Assuming none of that changed, one idea.
On some motherboards, I've seen the BMC internally "lose its connection" to the serial chip, thus it doesn't get any serial data and thus doesn't have anything to send out. Unfortunately a hard power reset is often needed to solve this (b/c the BMC always is "on" via standby power, it must be a hard reset to reset it). Hard resetting the BMC directly might work as well, you can do this in FreeIPMI via bmc-device --cold-reset.
Finally, I've found what was going on.
It happened that somehow a value DID change on the BIOS settings, most likely my own mistake: remote connection ability was disabled. That means, it seems, that SOL works, but it doesn't redirect anything. Given that I was able to connect through SOL, it seemed obvious that remote connection ability was enabled.
Once enabled that BIOS setting, everything was back to normal.
BTW: freeipmi is awesome. Thanks for maintaining it Albert.

Hosting multiple clients with freemodbus

I am working on a project involving a microcontroller communicating to a PC via Modbus over TCP. My platform is an STM32F4 chip, programming in C with no RTOS. I looked around and found LwIP and Freemodbus and have had pretty good success getting them both to work. Unfortunately, I'm now running into some issues which I'm not sure how to handle.
I've noticed that if I establish connection, then lose connection (by unplugging the Ethernet cable) I will not be able to reconnect (once I've plugged back in, of course). Freemodbus only allows one client and still has the first client registered. Any new clients trying to connect are ignored. It won't drop the first client until after a specific timeout period which, as far as I can tell, is a TCP/IP standard.
My thoughts are...
I need a Modbus module that will handle multiple clients. The new client request after communication loss will be accepted and the first client will eventually be dropped due to the timeout.
How do I modify Freemodbus to handle this? Are there examples out there? I've looked into doing it myself and it appears to be a decently sized project.
Are there any good Modbus packages out there that handle multiple clients, are not too expensive, and easy to use? I've seen several threads about various options, but I'm not sure any of them meet exactly what I need. I've had a hard time finding any on my own. Most don't support TCP and the ones that do only support one client. Is it generally a bad idea to support multiple clients?
Is something wrong with how I connect to the microcontroller from my PC?
Why is the PC changing ports every time it tries to reconnect? If it kept the same port it used before, this wouldn't be a problem
Should I drop the client from Freemodbus as soon as I stop communicating?
This seems to go against standards but might work.
I'm leaning towards 1. Especially since I'm going to need to support multiple connections eventually anyways. Any help would be appreciated.
Thanks.
If you have a limit on the number of modbus clients then dropping old connections when a new one arrives is actually suggested in the modbus implementation guide (https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf)
Nevertheless a mechanism must be implemented in case of exceeding the number of
authorized connection. In such a case we recommend to close the oldest unused
connection.
It has its own problems but everything is a compromise.
Regarding supporting multiple clients...if you think about modbus/rs server - it could only ever have one master at a time. Then replace the serial cable with TCP and you see why it's not uncommon to only support one client (and of course it's easier to program). It is annoying though.
Depending on what you are doing you wont need the whole modbus protocol and implementing the parts you do need is pretty easy. Of course if you have to support absolutely everything its a different prospect. I haven't used freemodbus, or any other library appropriate to your setup, so I can't help with suggestions there.
Regarding the PC using different TCP source port each time - that is how TCP is supposed to work and no fault on your side. If it did reuse the same source port then it wouldn't help you because e.g. sequence numbers would be wrong.
Regarding dropping clients. You are allowed to drop clients though its better not to. Some clients will send a modbus command, notice the connection has failed, reconnect, but not reissue the command. That may be their problem but still nicer to not see it that often where possible. Of course things like battery life might make the calculation different.

Trouble proxying into computer

I am trying read traffic from a couple of test mobile devices, iphones, androids etc. I've done this for over a year using primarily Fiddler but also Charles. I did it up until yesterday without any issue. But today the devices do not appear to be connecting to my computer. I have confirmed that everything is configured right eg. device is set to use my computer as a proxy after I put in my computers IP address that I got by doing a simple ipconfig, sorry if this all sounds redundant but just letting you know my steps, better to have more information than less. I also turned off my firewall no change.
I thought perhaps something was done to our network, but I installed Fiddler on a coworkers computer and was able to proxy into that computer without any issue. Confirmed all drivers are up to date and really there was no change between yesterday and today except a deep scan with Malwarebites. Frankly sort of at a loss for what it might be, I have reinstalled Fiddler on my computer (the primary one I use, didn't reinstall Charles cause I don't want to deal with license issue right now) but at same time what are the chances that both stopped working at same time.
There's a high likelihood that your PC's firewall is blocking the inbound connection. You should check your firewall configuration to see if it's configured to allow inbound connections to Fiddler.
On your Fiddler-running PC, ensure Tools > Fiddler Options > Connections > Allow Remote Computers to connect is checked (if not, check it and restart).
From your co-worker's PC, try visiting http://<FiddlerPCName>:8888/ in the browser. Does the traffic appear in Fiddler?

Send a message to a machine that is powered off

I would like to send a message, or something can be an advise from a pc to an another pc (only one, or at the most 2), the latter is powered off.
The pc which should send the message is a windows server 2003 os, instead the pc which should receive the message is a windows xp os.
The two machines are in the same domain and they work together through an ingres database.
The message will be sent at night, because there is an ingres database back up procedure that runs at night when my pc will be powered off, but when in the morning i will be at work I would like to read this message as a net send message, or something like
Unfortunately the net send command is disabled in our network, so I can't use it, but i'm looking a way for sending this message.
Have you any suggestion? thank you
Use age-old simple file based messaging.
Store a message in a specific file in the server and write a simple application which runs on startup on your machine to read it and display it.
And this is apart from rerun's great suggestion :)
There is breaking new technology available called email.
Is the machine powered off or in standby?
If if is in standby, then I will defer to someone who may have a better idea of how to get wake the machine to wake up programatically(sp?).
If it is powered off then read on...
If you have access to the machines bios settings, then I would suggest scheduling a power on event in the range of the time before the backup normally completes.
Then it is a matter of receiving the message and optionally shutting back down afterward?
If you are unable to change the bios settings, then does the machine "power on after power loss?" If so, get a programmable timer from the nearest retail store and power off before leaving at night and have the timer set to power on before the time the backup could reasonably be completed.
This is not really a software solution per se, but your problem does seem to be mostly hardware related (with the power off requirement and all...)

Recovering from ipconfig /release on a remote PC [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Not strictly a programming question, but I was programming at the time and couldn't find an answer, so I thought, "Hey, I'll give StackOverflow a try!"
So I'm connected to my Windows XP work PC over a Remote Desktop connection through VPN. In a command window (on the remote PC), I foolishly type ipconfig /release. A split second before I come to my senses, I hit Enter. D'oh!
So what now? Am I hosed until I get to the office Monday morning? Any way to remotely make my office PC get itself a new IP address?
If it makes you feel any better, most of us have done something similar. I can't offer a suggestion that doesn't involve human intervention, but I can offer two ways to prevent a "next time" for you:
Look into a remote power controller. Cheap (inexpensive, hobbyist-grade) options are available through www.x10.com; other vendors (Pulizzi, DataProbe, etc.) provide more reliable solutions for a higher price. You may even be able to find a UPS that allows you to control it via a serial port.
Plug your PC into the power controller, and find a second PC to control it. Now you can reboot your PC remotely, no matter how badly you de-configure it.
Anticipate and compensate. It's reasonable to expect that you may need to release/renew the IP address again, so write a utility that will check for the loss of IP address and reboot if that occurs. For example, ping your default gateway and reboot if the ping fails consistently. Just be sure to anticipate the consequences of an unexpected reboot!
Try giving a call to the office and get someone(if any) to restart your computer or ipconfig /renew
What you need to do, is find some way to cut the power to your PC. Many PCs are configured by default to reboot if there is a power failure. So, just hack into your power grid, and shut off power to the entire building. Once your computer reboots, along with all the other equipment, your computer should have it's IP back.
(This probably won't work)
I think if you get your network connection severed, it'll reset (like, if I run ipconfig /release, then shut off my router and restart it, I get a new IP).
It'd be well winging it, but if I was desperate I'd hook up to my DHCP server and reboot it.. I predict the end result would be me still not being able to connect, and the admins giving me a good whipping.
Log into the managed switch the PC is connected to, shutdown the port, wait a few seconds, and then bring it back up. If you don't have a managed switch or no access to it, wait until Monday.

Resources