Esp8266 automatic restart modem

Hi im asking for help

I want to program this to automatically restart my modem if internet is down.

Do i ordered the correct item to this project.

Any one help me with the code? I searched online and found this one but i cant manage to keep this work.

Code

#include ESP8266WiFi.h

const char* ssid = "yourssid"; // Your ssid
const char* password = "yourpassword"; // Your Password
const char* testHostname = "www.google.com";
IPAddress HostIP;
unsigned int localPort = 80;
const int RELAY_Pin = 0; //Relay Pin

#define MINUTES (60L * 1000)
#define SECONDS 1000
const unsigned long PROBE_DELAY = 5 * MINUTES;
const unsigned long RESET_DELAY = 15 * MINUTES;
const unsigned long RESET_PULSE = 30 * SECONDS;
int Nreset_events = 0;

enum {
TESTING_STATE=0, FAILURE_STATE=1, SUCCESS_STATE=2
};

int CurrentState = TESTING_STATE;

void setup() {
pinMode(RELAY_Pin, OUTPUT);

Serial.begin(115200);
delay(10);
Serial.println( __FILE__ );
delay(10);

// Connecting to a WiFi network
Serial.print(String("Connecting to ") + ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    delay(500);
}
Serial.println("\nWiFi connected");

}

void reset_device() {
// keep track of number of resets
Nreset_events++;
Serial.println(String("\nDisconnected... resetting - ") + String(Nreset_events));
digitalWrite(RELAY_Pin, HIGH);
delay(RESET_PULSE);
digitalWrite(RELAY_Pin, LOW);
}

void loop() {
switch (CurrentState) {

    case TESTING_STATE:
        if (!WiFi.hostByName(testHostname, HostIP)) {
            CurrentState = FAILURE_STATE;
        } else {
            CurrentState = SUCCESS_STATE;
        }
        break;

    case FAILURE_STATE:
        reset_device();
        delay(RESET_DELAY);
        CurrentState = TESTING_STATE;
        break;

    case SUCCESS_STATE:
        delay(PROBE_DELAY);
        CurrentState = TESTING_STATE;
        break;
}

}


pls put your code between code-tags

How can i do that sir? Can you help me please

sir, do the right formatting of inserted code. pls sir.