使用批处理,如何确定您是否连接到wifi网络? [英] Using batch, how to determine whether or not you are connected to a wifi network?

查看:235
本文介绍了使用批处理,如何确定您是否连接到wifi网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 netsh wlan connect name =your network_name您可以请求连接到WiFi网络,但无法确定您是否已连接。



那么,在Batch中,检查我是否连接到WiFi网络的命令行是什么? (WiFi网络可能有也可能没有网络访问权限。)



如果已连接,则应显示YES,



如果没有连接,它应该显示NO,



因为我想根据我得到的结果运行一个循环。



所以有人可以编写好的工作批处理程序!或c ++(如果可能的话)



我尝试过:



WMIC / node:PutYourPCNameHere路径WIN32_NetworkAdapter其中(NetConnectionID =Wi-Fi)获取NetConnectionStatus



但我们不能放置if循环。所以我不知道怎么办!!







Using netsh wlan connect name="your network_name" you can request to connect to a WiFi network, but can't be sure whether or not you are connected.

So, in Batch, what would be a command line to check whether or not I am connected to a WiFi network? (The WiFi network may, or may not, have network access.)

If Connected, It should display YES,

If NOT Connected, It should display NO,

because I want to run a loop depending upon the results I get.

So can someone write good working batch program!! or c++(if possible too)

What I have tried:

WMIC /node: "PutYourPCNameHere" path WIN32_NetworkAdapter where (NetConnectionID="Wi-Fi") get NetConnectionStatus

but we cant put if loops. So I dont know How to proceed !!

or

@echo off
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF     ERRORLEVEL 1 goto :TRYAGAIN

:TRYAGAIN
ECHO FAILURE!
ECHO Let me try a bit more, please wait...
@echo off
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS2
IF     ERRORLEVEL 1 goto :TRYIP

:TRYIP
ECHO FAILURE!
ECHO Checking DNS...
ECHO Lets try by IP address...
@echo off
ping -n 1 216.239.37.99|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESSDNS
IF     ERRORLEVEL 1 goto :TRYROUTER

:TRYROUTER
ECHO FAILURE!
ECHO Lets try pinging the router....
ping -n 2 192.168.1.1|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :ROUTERSUCCESS
IF     ERRORLEVEL 1 goto :NETDOWN

:ROUTERSUCCESS
ECHO It appears that you can reach the router, but internet is unreachable.
goto :FAILURE

:NETDOWN
ECHO FAILURE!
ECHO It appears that you having network issues, the router cannot be reached.
goto :FAILURE

:SUCCESSDNS
ECHO It appears that you are having DNS issues.
goto :FAILURE

:SUCCESS
ECHO You have an active Internet connection
pause
goto END

:SUCCESS2
ECHO You have an active internet connection but some packet loss was detected.
pause
goto :END

:FAILURE
ECHO You do not have an active Internet connection
pause
goto :END

:END





但这无法解决热点和其他无线网络但没有网络连接。



But this fail to work over hotspots and other wifi but no internet connections.

推荐答案

netsh wlan show interfaces | Findstr / c:信号&& Echo Online || Echo离线

离线
netsh wlan show interfaces | Findstr /c:"Signal" && Echo Online || Echo Offline
Offline


这篇关于使用批处理,如何确定您是否连接到wifi网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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