Network config

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Network config

#1 Post by mor.bas » 10 Mar 2013 03:33

Hi
I have 20 network card in my server.
I need a script the get over all the card and changed all the dhcp card to be disable.
i know that i doing it with netsh but how exactly?
Thanks in advance....

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#2 Post by foxidrive » 10 Mar 2013 06:35

How will you set static IP addresses? Disabling dhcp is not the whole task, right?

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Network config

#3 Post by mor.bas » 10 Mar 2013 06:37

Yes I already set there all the Ip address
Now I need a script to disable of the nic's that are dhcp(dynamic ip).

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#4 Post by foxidrive » 10 Mar 2013 06:40

I'm confused. Do you want to disable the NICs that are set to DHCP?

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Network config

#5 Post by mor.bas » 10 Mar 2013 06:47

yes you right.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#6 Post by foxidrive » 10 Mar 2013 06:52

Can you paste the output of this into a code block? I need to see what kind of output the command gives on your server.

Code: Select all

@echo off
ipconfig /all |findstr /i /c:"ethernet adapter " /c:"dhcp enabled"
pause

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Network config

#7 Post by abc0502 » 10 Mar 2013 07:11

This can detect if dhcp enabled or disabled, but after foxidrive asked for your output, i'm not sure if it will work for you too or not :?

Code: Select all

@Echo OFF
Rem Detect if dhcp enabled or disabled
For /F "delims=" %%A In ('IPconfig /ALL ^|FINDstr /C:"Dhcp Enabled"') Do (
   For /F "tokens=2 delims=:" %%B In ("%%A") Do (
      IF "%%B" == " Yes" ( echo it's enabled
         ) Else ( echo disabled )
   )
)
Pause
you can then disable the NIC adapter with the command netsh

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Network config

#8 Post by mor.bas » 10 Mar 2013 07:27

Ethernet adapter LAN 04:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 03:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter 2:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 01:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 10:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 09:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 05:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 07:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 08:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 11:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 12:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 14:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 15:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 16:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 06:
DHCP Enabled. . . . . . . . . . . : Yes
Ethernet adapter LAN 13:
DHCP Enabled. . . . . . . . . . . : Yes
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No
DHCP Enabled. . . . . . . . . . . : No

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#9 Post by foxidrive » 10 Mar 2013 08:12

Try this command and see what it outputs:

Code: Select all

wmic nicconfig where dhcpenabled='true' get description,index

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Network config

#10 Post by mor.bas » 10 Mar 2013 08:33

Description Index
Intel(R) PRO/1000 PT Dual Port Server Adapter 7
Intel(R) PRO/1000 PT Dual Port Server Adapter 11
Intel(R) PRO/1000 PT Dual Port Server Adapter 13
Intel(R) PRO/1000 PT Dual Port Server Adapter 15
Intel(R) PRO/1000 PT Dual Port Server Adapter 16
Intel(R) PRO/1000 PT Dual Port Server Adapter 18
Intel(R) PRO/1000 PT Dual Port Server Adapter 20
Intel(R) PRO/1000 PT Dual Port Server Adapter 23
Intel(R) PRO/1000 PT Dual Port Server Adapter 24
Intel(R) PRO/1000 PT Dual Port Server Adapter 26
Intel(R) PRO/1000 PT Dual Port Server Adapter 28
Intel(R) PRO/1000 PT Dual Port Server Adapter 30
Intel(R) I350 Gigabit Network Connection 33
Intel(R) I350 Gigabit Network Connection 34
Intel(R) Ethernet Controller X540-AT2 36
Intel(R) Ethernet Controller X540-AT2 38

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#11 Post by foxidrive » 10 Mar 2013 09:50

Then if all those adapters are NICs then this should work to disable them (untested):

Code: Select all

@echo off
for /f "skip=1" %%a in ('wmic nicconfig where dhcpenabled^='true' get index') do (
wmic path win32_networkadapter where index=%%a call disable
)
pause


In Windows 8 I get another adapter called "Microsoft Kernel Debug Network Adapter" and that's probably not a good thing to disable randomly, so the code would need to filter it out if it was used in Windows 8.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Network config

#12 Post by mor.bas » 11 Mar 2013 01:01

It doesn't work.
I got on the screen the message: true - invalid alias verb.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#13 Post by foxidrive » 11 Mar 2013 06:54

Try it now - I escaped the = sign.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Network config

#14 Post by mor.bas » 11 Mar 2013 07:48

No it's work bit in the end I got an error
Description=invalid query

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Network config

#15 Post by foxidrive » 11 Mar 2013 15:21

You can ignore that error. The WMIC output has embedded carriage returns and that entry has a blank carriage return.

Post Reply