MSFN Forum: IP settings based on MAC address..? - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

IP settings based on MAC address..? help needed...any scripts/tools out there? Rate Topic: -----

#1 User is offline   gparmar 

  • Newbie
  • Group: Members
  • Posts: 11
  • Joined: 18-October 05

Posted 25 October 2005 - 11:50 AM

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


#2 User is offline   jjvs 

  • Newbie
  • Group: Members
  • Posts: 27
  • Joined: 21-June 05

Posted 14 November 2005 - 08:24 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy