Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.chrome.ChromeOptions;
- import java.net.InetAddress;
- import java.util.List;
- public class InternetReachable {
- // auto reboot R850 if internet is down
- private static int testCount = 10;
- private static double validityPercentage = 0.5;
- private static String testAddr = "8.8.8.8";
- private static String resetAddr = "http://192.168.128.1/hidden/data-lte.html";
- private static int timeout = 10000;
- public static void main(String[] args) throws Exception {
- monitorProcess();
- }
- private static void monitorProcess() throws Exception{
- while(true){
- if(isGoodConnection(testAddr, timeout)){
- System.out.println("Good connection, check again in 5 minutes.");
- Thread.sleep(1000 * 60 * 5);
- }else{
- System.out.println("Bad connection, resetting modem.");
- System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
- ChromeOptions chromeOptions = new ChromeOptions();
- chromeOptions.addArguments("--headless");
- WebDriver driver = new ChromeDriver(chromeOptions);
- driver.get(resetAddr);
- List<WebElement> applyButtons = driver.findElements(By.cssSelector("button.brick-actor"));
- // System.out.println(applyButtons.size());
- Thread.sleep(1000);
- if(applyButtons.size() == 0){
- System.out.println("No connection to R850, wait 1 minute and check again.");
- Thread.sleep(1000 * 60);
- continue;
- }
- applyButtons.get(1).click();
- WebElement accept = driver.findElement(By.cssSelector("button.modal-btn1"));
- Thread.sleep(1000);
- accept.click();
- Thread.sleep(1000);
- driver.quit();
- System.out.println("R850 rebooted, wait about 1 minute for it to boot up.");
- System.out.println("Wait 5 minutes for next check.");
- Thread.sleep(1000 * 60 * 5);
- }
- }
- }
- private static boolean isGoodConnection(String address, int timeout) throws Exception{
- InetAddress ia = InetAddress.getByName(address);
- boolean[] flags = new boolean[testCount];
- for(int i = 0; i < testCount; i++)
- flags[i] = ia.isReachable(timeout);
- int validCount = 0;
- for(boolean flag : flags) validCount += flag ? 1 : 0;
- if(validCount >= testCount * validityPercentage) return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement