Smart devices - advising lost LAN contact

Joined
30 Dec 2018
Messages
20,316
Reaction score
3,567
Location
Up North
Country
United Kingdom
I have looked a few times, to see if there was any sort of built in way for Alexa to advise me if contact was lost with one of the devices it controlled, because some of them I use it to automatically control could become quite critical, like the Smart Plug which keeps my car's battery topped up each day, as it is tucked away in the garage, out of sight, out of mind.

Failing to find anything built in, I went looking for a ping utility, which warns if a ping fails to be responded to. If a LAN device responds to a ping, it's a fair assumption that it is working OK. Ping Monster is one I found, which will do that and it is quite small and very configurable, you can set it to make a noise on the PC, log failures and send an email to yourself, even to allow several failed pings in succession before issuing a warning.
 
I cannot seem to get the email of the utility to work, despite checking my settings several times and trying variations - pressing test email doesn't deliver a test message to any of the three email addresses I have tried.
 
Nirsoft PingInfoView seems a more up to date utility, but lacks the built in ability to send email, but a Shell script can be set up to send an email - I still have not managed to receive an email, despite trying three different send addresses, with both utils - something weird.
 
Sorry, silly question, but have you named the correct SMTP server?
AV, or firewall blocking the scripts?
 
Last edited:
...and the messages havent turned up in spam?!!! :)

No, nothing delivered at all, in any of the accounts. I see a brief flash of blue as the what I assume the Powershell script runs, which implements the send email, when it is triggered.

This is the script.. First four lines are modified to include my email details. The "587" near the bottom, I assume is the port it should attempt to connect to on the mailserver.

I have just had a bright idea - Should those first four lines have the quotes marks around the items, should this $Username = "YourMailUser"; actually be $Username = YourMailUser; ????

$Username = "YourMailUser";
$Password = "YourMailPassword";
$SendTo = "[email protected]";
$MailServer = "mail.yourdomain.com";
$HostName = $args[0];
$IPAddress = $args[1];
$PingStatus = $args[2];
$FailedOn = $args[3];

$message = new-object Net.Mail.MailMessage;
$message.From = $Username;
$message.To.Add($SendTo);
$message.Subject = "Failed Ping On $HostName" ;
$message.Body = "Information about the failed ping: `r`nHost Name: $HostName`r`nIP Address: $IPAddress`r`nPing Status: $PingStatus`r`nPing Time: $FailedOn";

$smtp = new-object Net.Mail.SmtpClient($MailServer, "587");
$smtp.EnableSSL = $true;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message);
 
I think there is a way to step through and troubleshoot scripts - Set-PSDebug might do it?
I also suspect the quotes should remain in place :)
But as this has happened with different apps, i would guess it may be an admin rights, AV, or firewall issue :(
 
A bit of progress...

If I open a Powershell console, copy, paste and run the script - the email is sent and received. So it's the actual software failing to run the script, rather than the script at fault..

It suggests...

Now you have to update PingInfoView to run the PowerShell script when a ping fails. In PingInfoView, press F9 ('Advanced Options' window), select the 'Execute the following command on failed ping' option and then type the command to run the PowerShell script: Powershell.exe -executionpolicy remotesigned -File F:\Scripts\send_message_failed_ping.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"

In the above command example, the script is saved on F:\Scripts\send_message_failed_ping.ps1, and obviously you have to put the correct script filename on your system.

Which I have done - Powershell.exe -executionpolicy remotesigned -File C:\Program Files\Nirsoft\send_message_failed_ping.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"

C:\Program Files\Nirsoft\send_message_failed_ping.ps1 is where the script file is located.
 
Last edited:
A bit of progress...

If I open a Powershell console, copy, paste and run the script - the email is sent and received. So it's the actual software failing to run the script, rather than the script at fault..
Well done! Getting somewhere - have you tried running the script command outside of the app?
I.e. from the example:
Powershell.exe -executionpolicy remotesigned -File F:\Scripts\send_message_failed_ping.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"
If this fails, then its not the apps fault, and we may be back to rights issues?
 
I.e. from the example:
Powershell.exe -executionpolicy remotesigned -File F:\Scripts\send_message_failed_ping.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"
If this fails, then its not the apps fault, and we may be back to rights issues?

Which produces....

PS C:\WINDOWS\system32> Powershell.exe -executionpolicy remotesigned -File C:\Program Files\Nirsoft\send_message_failed_ping.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"
Processing -File 'C:\Program' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.
 
Paste the script into notepad and save as a .ps1 file? (Not a .txt!)
If you pasted the script into another editor, there's the possibility of a hidden file extension, not just the .ps1 on the end of the file.
 
Paste the script into notepad and save as a .ps1 file? (Not a .txt!)
If you pasted the script into another editor, there's the possibility of a hidden file extension, not just the .ps1 on the end of the file.

It was saved as a .ps1, in Notepad. I changed the name to 'failed.ps1' - saved and exactly the same issue as above.

Right clicking on the renamed 'failed.ps1' and selecting 'Run with Powershell' - it works fine, sends the email and it gets delivered. But it still doesn't work when called by the Nirsoft software.
 
Have just tried it and it works fine for me.
Did you definitely change the "save as type" to "all files" in notepad?
Does the file "type" of the script show up as "Windows powershell script" in Windows explorer?
 
Yes, I definitely changed and yes it show up in explorer as a windows script. The only fault with it is that the Nirsoft software fails to run the script.
 
Back
Top