#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. ELK系列~nxlog实现多位置文件的收集

    前几天我写了几篇关于ELK日志收集,存储和分析的文章: ELK系列~NLog.Targets.Fluentd到达如何通过tcp发到fluentd ELK系列~Nxlog日志收集加转发(解决log4日志 ...

  2. MapReduce-实践1

      MR进阶实践1:  -file 分发多个文件 [-file 适合场景]分发文件在本地,小文件 -file分发原理         run.sh文件: 通过多个-file, 将多个本地文件分发到Ha ...

  3. 微信公众平台开发接口PHP SDK

    以前没接触过微信公众平台开发,前几天刚找到实习公司就要求我做一个微信公众平台的应用,于是乎开始学习微信公众平台开发接口的调用,看开发文档之后还是不知道从何入手,只好上网找入门资料,终于在方倍工作室找到 ...

  4. LeetCode 190. Reverse Bits (反转位)

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  5. ES6中函数新增的方式方法

    ---恢复内容开始---   绪 言 ES6 大家对JavaScript中的函数都不陌生.今天我就为大家带来ES6中关于函数的一些扩展方式和方法. 1.1函数形参的默认值 1.1.1基本用法 ES6 ...

  6. xml文件的方式实现动态代理基于SpringAOP

    1.配置spring容器 导入jar包 com.springsource.net.sf.cglib-2.2.0.jar com.springsource.org.aopalliance-1.0.0.j ...

  7. Java8 函数式编程详解

    Java8 函数式编程详解 Author:Dorae Date:2017年11月1日23:03:26 转载请注明出处 说起Java8,可能很多人都已经知道其最大的改进,就是引入了Lambda表达式与S ...

  8. hdu 2089 不要62(入门数位dp)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. Problem E: 动物爱好者

    Problem E: 动物爱好者 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 882  Solved: 699[Submit][Status][Web ...

  10. EasyWcf------无需配置,无需引用,动态绑定,轻松使用

    设计原则:万物皆对象 前言:在上一篇的0配置使用Wcf中,虽然使用已经很方便了,但是对于最求极致简洁得人来说(比如我),客户端需要通过手动引用服务才能够调用服务接口,那么有没有办法能够绕过手动引用这一 ...