#powershell 监控, 重启网卡

一台Windows服务器,由于负荷较大,偶尔会网络中断,就写了个powershell脚本,监控ip是否通,不通就重启网卡

cls
$host.UI.RawUI.WindowTitle = ‘……VM监控……’
$host.UI.RawUI.ForegroundColor='Green'
#version V1.3.9
#t1间隔时间s
$t1=5
$log='C:\Router.log.txt'
#region
$nu=0
$n1="##########"
$n2="监控总次数"
$cq1=0
$cq2=0
$ip1='192.168.0.1'
$ip2='172.16.11.145'
$ip3='172.16.11.8'
#endregion
if(Test-Path $log){}else
{
"初始化log"
echo $n1 >$log
echo $n2 >>$log
echo $nu >>$log
echo $n1 >>$log
}
while(1 -lt 2)
{
sleep $t1
cls
$log1=Get-Content $log
$nu=$log1[2]
$nu=[int]$nu + 1
#print
echo $n1
echo "$($n2):$($nu)"
echo "监控间隔:$($t1)s"
echo "重启网卡:$($cq1)"
echo "重启路由:$($cq2)"
echo $n1
#write
echo $n1 >$log
echo $n2 >>$log
echo $nu >>$log
echo $log1[3..($log1.count-1)] >>$log #check
if ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip1'").StatusCode -eq 0)
{
"The router is online!"
#检测内网
if ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip2'").StatusCode -eq 0)
{ "The Lan is online!" }
elseif ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip3'").StatusCode -eq 0)
{ "The Lan is online!" }
else
{
"重启内网网卡"
$cq1=$cq1 + 1
echo "重启内网网卡, $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ffff')">>$log
Get-NetAdapter -Name '本地连接' | Restart-NetAdapter
Get-NetAdapter -Name 'Lan' | Restart-NetAdapter
sleep 30
}
}
else
{
"The router is offline!"
"重启路由网卡"
$cq1=$cq1 + 1
echo "重启路由网卡, $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ffff')">>$log
Get-NetAdapter -Name 'Wan2' | Restart-NetAdapter
Get-NetAdapter -Name 'Lan2' | Restart-NetAdapter
sleep 30
#再次检测
if ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip1'").StatusCode -eq 0)
{ "The route is online!" }
else
{
"重启 router"
$cq2=$cq2 + 1
echo "重启 router, $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ffff')">>$log
$vname='ikuai-router'
Restart-VM $vname -Force
sleep 100
}
}
}

powershell 监控, 重启网卡的更多相关文章

  1. shell监控网卡状态,故障时自动重启网卡

      今天朋友找我写个监控网卡状态的脚本,要求在系统网卡挂了可以自己启动起来,这个要求是不是很bt,我考虑了半天,简单的写了个shell脚本来监控,实现原理是使用ping来测试网络连通性,如果不通就重启 ...

  2. [AlwaysOn Availability Groups]使用Powershell监控AlwayOn健康

    使用Powershell监控AlwayOn健康 1.基本命令概述 AlwayOn Dashboard是很有用的查看整体AG健康状况的工具.但是这个工具不是用于7*24监控的.如果应用程序夜间发送严重的 ...

  3. Linux:Vmware安装linux虚拟机,桥接方式配置静态IP后重启网卡,提示:Error,some other host already uses address 10.252.252.21...

    问题: Vmware安装linux虚拟机,桥接方式配置静态IP后重启网卡,提示:Error,some other host already uses address 10.252.252.21... ...

  4. 【转】ubuntu 重启命令,ubuntu 重启网卡方法

    ubuntu 重启命令 重启命令:1.reboot2.shutdown -r now 立刻重启(root用户使用)3.shutdown -r 10 过10分钟自动重启(root用户使用)4.shutd ...

  5. ubuntu 重启命令,ubuntu 重启网卡方法

    ubuntu 重启命令 重启命令:1.reboot2.shutdown -r now 立刻重启(root用户使用)3.shutdown -r 10 过10分钟自动重启(root用户使用)4.shutd ...

  6. 重启网卡报错:Device eth0 does not seem to be present

    ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting down loopback insterface:  ...

  7. 在VMware的虚拟机中克隆CentOS,在重启网卡的时候报错解决办法

    克隆虚拟机配置 1.修改:vi /etc/hosts 2.修改:vi /etc/sysconfig/network 3.重启生效:reboot或者init 6 如不重启可以输入:hostname  新 ...

  8. Linux 重启网卡失败 Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.

    linux下重启网卡使用命令 : service network restart 时报错: [root@slave01 hadoop]# service network restart Startin ...

  9. Ubuntu重启网卡的三种方法

    一.network利用root帐户# service network restart 或者/etc/init.d/networking restart 二.ifdown/ifup# ifdown et ...

随机推荐

  1. LeetCode 31. Next Permutation (下一个排列)

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  2. 【SQL注入】mysql中information_schema详解

    在MySQL中,把 information_schema 看作是一个数据库,确切说是信息数据库.其中保存着关于MySQL服务器所维护的所有其他数据库的信息.如数据库名,数据库的表,表栏的数据类型与访问 ...

  3. 走进 Xamarin Test Recorder for Xamarin.Forms

    此篇是承接之前 走进 UITest for Xamarin.Forms 的,所以如果没有看过之前的可以先看下之前的 UITest 比起上一篇纯敲代码只适合程序员的 UITest ,这一篇不管是程序员还 ...

  4. 使用prettytable美化python的print输出

    经常碰到需要将一些数据用表格形式输出来.自己手动写太麻烦. 用prettytable能很好解决这个问题. ...(未完)

  5. [译]ASP.NET Core 2.0 路由引擎之网址生成

    问题 如何在ASP.NET Core 2.0中由路由引擎来生成网址? 答案 新建一个空项目,修改Startup.cs文件,添加MVC服务和中间件: public void ConfigureServi ...

  6. 业余草双因素认证(2FA)教程

    所谓认证(authentication)就是确认用户的身份,是网站登录必不可少的步骤.密码是最常见的认证方法,但是不安全,容易泄露和冒充.越来越多的地方,要求启用双因素认证(Two-factor au ...

  7. github创建远程仓库

    创建远程仓库 当你已经在本地创建了一个Git仓库后,又想在GitHub创建一个Git仓库,并且让这两个仓库进行远程同步,这样,GitHub上的仓库既可以作为备份,又可以让其他人通过该仓库来协作,真是一 ...

  8. C#中的静态成员和非静态成员

    C#的类中可以包含两种方法:C#静态方法与非静态方法.那么他们的定义有什么不同呢?他们在使用上会有什么不同呢? 让我们来看看最直观的差别:使用了static 修饰符的方法为静态方法,反之则是非静态方法 ...

  9. C#中窗体的close,dispose,以及application.exit()的区别

    close关闭窗体,对象仍然存在,调用Close函数释放资源后可能还需要再次使用. dispose,销毁对象,窗体对象被回收了,也就是不存在了,Dispose函数释放的资源不再使用. applicat ...

  10. [转载] Hadoop MapReduce

    转载自http://blog.csdn.net/yfkiss/article/details/6387613和http://blog.csdn.net/yfkiss/article/details/6 ...