my workstation has couple of network cards, have default interface names this: local area connection, local area connection 2, etc.
it may network card 1 named local area connection 3, network card 2 named local area connection etc.
i trying write batch (preferred) or vbs script following:
- check, whether specific network card installed in machine has 1 of mac addresses of predefined list
- get interface name of network card
- change interface name of network card
- change configuration of network card (ip address, subnet mask)
so far, found out change interface name using command line:
netsh interface set interface name="local area connection" newname="newnetworkname" and change configuration using:
netsh int ip set address "local area connection" static 192.168.0.101 255.255.255.0 0.0.0.0 so question how realize step 1. , step 2.
any appreciated.
using
ipconfig /allon system english system language:@echo off setlocal enabledelayedexpansion set maclist=01-02-03-04-05-06 aa-bb-cc-dd-ee-ff /f "delims=" %%a in ('ipconfig /all') ( set line=%%a if not "!line:~0,1!"==" " if not "!line:adapter=!"=="!line!" ( set name=!line:*adapter =! set name=!name::=! ) /f "tokens=1,2,*" %%b in ("%%a") ( if "%%b %%c"=="physical address." ( set mac=%%d set mac=!mac:*: =! echo !name!: !mac! call set mactest=%%maclist:!mac!=%% if not "!maclist!"=="!mactest!" ( netsh interface set interface name="!name!" newname="newnetworkname1" netsh int ip set address "newnetworkname1" static 192.168.0.101 255.255.255.0 0.0.0.0 ) ) ) ) pauseusing
getmac(takes 1 sec execute though), language-independent:@echo off setlocal enabledelayedexpansion set maclist=01-02-03-04-05-06 aa-bb-cc-dd-ee-ff /f "delims=" %%a in ('getmac /fo csv /nh /v') ( set line=%%a&set line=!line:"=,! /f "delims=,,, tokens=1,3" %%b in ("!line!") ( set name=%%b set mac=%%c call set mactest=%%maclist:!mac!=%% if not "!maclist!"=="!mactest!" ( netsh interface set interface name="!name!" newname="newnetworkname1" netsh int ip set address "newnetworkname1" static 192.168.0.101 255.255.255.0 0.0.0.0 ) ) ) pause
Comments
Post a Comment