-3

Info: some of our colleges use a network USB adapter that registers as "Ethernet 3" I need a way to determine if "Ethernet" or "Ethernet 3" is plugged in and set it as a variable, so I can execute a change ip. (Batch script)

netsh int ip set address "%Ethernet adapter%" static 192.168.0.186 255.0.0.0 192.168.0.1 1
feelfreek
  • 3
  • 1
  • 1
    Welcome as a new user to [SO]. Please take the [tour] and also read [ASK]. Before asking a question you should do research on your issue, there are several questions with promising answers to find easily. –  Jul 17 '18 at 14:47

1 Answers1

0

You can test if an internet is connected by using FOR /F & netsh interface show interface^|find "Connected". This will search for all connected networks to your device.

From here we can use echo %%B | findstr "Wi-Fi" > Nul to filter the result's down to the Wi-Fi and use IF %ERRORLEVEL% EQU 0 to tell if it exists or not (Thus telling us if its online or not)

FOR /F "tokens=3,*" %%A IN ('netsh interface show interface^|find "Connected"') DO echo %%B | findstr "Wi-Fi" > Nul
IF %ERRORLEVEL% EQU 0 (GOTO :CONNECTED) ELSE (GOTO :DISCONNECTED)

Not sure if you need both to be connected or not due to your lack of description, but to do this you change the (GOTO :CONNECTED) ELSE (GOTO :DISCONNECTED) to variables (example: (SET C1=ONLINE) ELSE (SET C1=OFFLINE)) and stack a new FOR /F for the next network. Then using an IF /I ""=="" statement, you can compare the variables to see if both are "Online".

IF /I "%C1%"=="ONLINE" (IF /I "%C2%"=="ONLINE" (GOTO :ONLINE) ELSE (GOTO :OFFLINE)) ELSE (GOTO :OFFLINE)

Be sure to use the following command to find the Interface Name of your network for the findstr command.

netsh interface show interface

John Kens
  • 1,615
  • 2
  • 10
  • 28