while (true)
{
string ip = obj.ToString().Split('|')[1];
string robsn = obj.ToString().Split('|')[0];
ChromeOptions options1 = new ChromeOptions();
// InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
// 不显示浏览器
options1.AddArgument("--headless");
options1.AddArgument("--disable-gpu");
options1.AddArgument("--disable-cache");
options1.AddArgument("--incognito");
options1.AddArgument("--first run");
// internetExplorerOptions.
IWebDriver driver = new ChromeDriver(options1); //new EdgeDriver(options1);
try
{
string url = "http://" + ip;
string url2 = "http://" + ip + "/doc/XPOF.html";
bool online = false;
Ping ping = new Ping();
PingReply pingReply = ping.Send(ip);
if (pingReply.Status == IPStatus.Success)
{
online = true;
Console.WriteLine(ip + " | 当前在线,已ping通!");
}
else
{
online = false;
Console.WriteLine(ip + " | 在线,ping不通!");
}
if (online)
{
driver.Navigate().GoToUrl(url);
var element = driver.FindElement(By.Name("password"));
var _element = driver.FindElement(By.Name("goto"));
element.SendKeys("admin");
_element.Click();
driver.Navigate().GoToUrl(url2);
driver.SwitchTo().Frame("XFrameTablePage");
var element_ = driver.FindElement(By.Name("XForm"));
var tbody_element = element_.FindElements(By.TagName("table"))[0].FindElements(By.TagName("tbody"))[0].FindElements(By.TagName("tr"))[0].FindElements(By.TagName("td"))[1].FindElements(By.TagName("table"))[0].FindElements(By.TagName("tbody"))[0];
string POF1 = tbody_element.FindElements(By.TagName("tr"))[1].FindElements(By.TagName("td"))[1].Text;
string POF2 = tbody_element.FindElements(By.TagName("tr"))[2].FindElements(By.TagName("td"))[1].Text;
string POF3 = tbody_element.FindElements(By.TagName("tr"))[3].FindElements(By.TagName("td"))[1].Text;
string sql;
string sql2 = "select * from rapidio where robsn='" + ip + "' and name in ('port2','port3','port4') order by updatetime desc";
DataTable dt = SqlHelper.ExecuteQuery(sql2);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string port = dt.Rows[i]["name"].ToString();
string pof = string.Empty;
switch (port)
{
case "port2":
pof = POF1;
break;
case "port3":
pof = POF2;
break;
case "port4":
pof = POF3;
break;
}
if (Convert.ToDateTime(dt.Rows[i]["updatetime"]).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
{
sql = "insert into rapidio(robsn,type,name,value,updatetime) values('" + ip + "','交换机数据','" + port + "','" + pof + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "')";
SqlHelper.ExecuteNonQuery(sql);
}
else
{
sql = "update rapidio set value='" + pof + "' where name = '" + port + "' and updatetime ='" + DateTime.Now.ToString("yyyy-MM-dd") + "' and robsn='" + ip + "'";
SqlHelper.ExecuteNonQuery(sql);
}
}
}
else
{
sql = "insert into rapidio(robsn,type,name,value,updatetime) values('" + ip + "','交换机数据','port2','" + POF1 + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "'),('" + ip + "','交换机数据','port3','" + POF2 + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "'),('" + ip + "','交换机数据','port4','" + POF3 + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "')";
SqlHelper.ExecuteNonQuery(sql);
}
string sqlcmd = "insert into exchangedata (robsn,exchangeip,name,value,updatetime) values('" + robsn + "','" + ip + "','port2','" + POF1 + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'),('" + robsn + "','" + ip + "','port3','" + POF2 + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'),('" + robsn + "','" + ip + "','port4','" + POF3 + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')";
SqlHelper.ExecuteNonQuery(sqlcmd);
}
}
catch (Exception e)
{
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + e.ToString());
}
options1 = null;
CloseChromeDriver(driver);
Thread.Sleep(sleeptime);
}
|