Created
March 16, 2016 09:57
-
-
Save philhawthorne/42223ab86798055e37dd to your computer and use it in GitHub Desktop.
CastleOS Conditional Script based on Pinging an IP Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using CastleOSCoreService; // NOTE: this must be included, but you can add other using statements below | |
using System.Net.NetworkInformation; | |
public class MyScript | |
{ | |
public string Main(string[] args) | |
{ | |
//Specify the IP address you want to check here | |
string ip_address = "192.168.1.x"; | |
Ping ping = new Ping(); | |
PingReply pingresult = ping.Send(ip_address); | |
if (pingresult.Status.ToString() == "Success") | |
{ | |
ScriptingAPI.WriteDatabaseEntry("IP Address is online"); | |
return "online"; | |
} else { | |
ScriptingAPI.WriteDatabaseEntry("IP Address is offline"); | |
return "offline"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment