Skip to content

Instantly share code, notes, and snippets.

@philhawthorne
Created March 16, 2016 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philhawthorne/42223ab86798055e37dd to your computer and use it in GitHub Desktop.
Save philhawthorne/42223ab86798055e37dd to your computer and use it in GitHub Desktop.
CastleOS Conditional Script based on Pinging an IP Address
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