确定是否已插入/拔出以太网[批处理代码]

编程入门 行业动态 更新时间:2024-10-25 08:19:17
本文介绍了确定是否已插入/拔出以太网[批处理代码]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 >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

更多推荐

确定是否已插入/拔出以太网[批处理代码]

本文发布于:2023-11-05 04:09:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批处理   以太网   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!