确定是否已插入/拔出以太网[批处理代码] [英] Determine if Ethernet is plugged/unplugged [batch code]

查看:96
本文介绍了确定是否已插入/拔出以太网[批处理代码]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于笔记本电脑的小脚本,我想做得更好.

I have a little script for a laptop and I want to make it better.

我希望该批处理确定以太网连接是否已插入.

I want the batch to determine if the Ethernet connection is plugged or not.

如果插入了以太网,我想使其通过rasdial连接并ping通.如果PC从ping收到响应,则显示连接成功建立".如果ping没有响应,则连接失败".

If Ethernet is plugged, I would like to make it connect via rasdial and to ping. If PC receives response from ping, then to show "Connection established successfully". If no response from ping, then "Connection failed".

如果拔出以太网,则显示无有线连接".

If Ethernet is unplugged, just to show "No wired connection".

这是当前代码:

@echo off

rasdial <Dialup_connection_name> <User> <Pass>

ping -n 1 -w 3000 www.google.com >nul
if errorlevel 1 (
  cls
  msg * Connection failed
  exit
)

cls
msg * Connection established successfully
exit

推荐答案

netsh interface show interface name="LAN-Verbindung" |find "Verbindungsstatus" |find "Verbunden">nul && echo connected || echo not connected

(这在德语窗口中有效;您必须对其进行本地化)

(this works on a german windows; you have to localize it)

要在批处理文件中看起来更好,可以这样编写:

to look nicer in the batchfile, you can write it like this:

netsh interface show interface name="LAN-Verbindung" ^
 |find "Verbindungsstatus" ^
 |find "Verbunden">nul ^
   && echo connected ^
   || echo not connected

这篇关于确定是否已插入/拔出以太网[批处理代码]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆