Jump to content

IP settings based on MAC address..?


Recommended Posts

Hello,

I have been looking out for a vb script or a s/w tool which will assign a specific IP based on the MAC address it reads from a txt file.

help me achieve this. it's very important to me.

any tools/how to/guides.

thanks in advance

Link to comment
Share on other sites

  • 3 weeks later...

Hi gparmar,

I think this cmd file should do the trick

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

REM Set the subnetmask
SET NETMASK=255.255.255.0

REM Retrieve "adapter name" & mac address using ipconfig
FOR /F "DELIMS=" %%M in ('IPCONFIG.EXE /ALL') DO @(
SET LINE=%%M
FOR /F "TOKENS=1" %%A IN ("!LINE!") DO @(
IF X%%A==XEthernet (
SET ADAPTER=!LINE:Ethernet adapter =!
SET ADAPTER=!ADAPTER::=!
SET MAC=
) ELSE IF X%%A==XPhysical (
SET MAC=!LINE:* : =!
REM Use Adapter with double quotes to submit full adaptername as 1 parameter
CALL :SET_IP !MAC! "!ADAPTER!"
)
)
)
GOTO END

:SET_IP
REM Read MAC & IP addresses from file, and if MAC is %1 set IP
FOR /F "TOKENS=1,2" %%I IN ('TYPE "%~dp0\mac2ip.txt"') DO IF %%I==%1 SET IP=%%J
IF DEFINED IP (
REM Update IP address for adapter
NETSH INTERFACE IP SET ADDRESS STATIC NAME=%2 %IP% %NETMASK%
) ELSE (
ECHO MAC Address not found in %~dp0\mac2ip.txt
)
GOTO END

:END

It reads the text file mac2ip.txt which should be in the same directory as this cmd file. And the text file looks something like this:

# MAC Address		IP Address
00-AA-11-BB-22-CC 10.10.10.101
00-DD-11-EE-22-FF 10.10.11.101
00-11-22-33-44-55 10.10.12.101

It can handle multiple ethernet adapters on one computer.

Good luck with it

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...