Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changine ip address with a batch file?

Status
Not open for further replies.

fenris

Programmer
May 20, 1999
824
0
0
CA
Is there a way to change the ip address, subnet mask and gateway of an NT 4 box using a batch file or some other mechanism that would be more automatic then manually changing them.

I have a number of clients using different ip address and I would like to have a batch file that would automatically configure my machine with a minimum of effort so my laptop can plug into their network.

Any ideas? Troy Williams B.Eng.
fenris@hotmail.com

 
All the ip's are static as all the client networks are relatively small and there are exotic devices like PLCs on the network that barely understand tcp/ip as it is.

DHCP would be rather easy.... Troy Williams B.Eng.
fenris@hotmail.com

 
:: You can try this as a batch file. I HAVE NEVER Tried
:: this in production!!!!!!!!!!!!!!!

:: %1 should be the Name of the Network Card
:: To find out the network card name for that PC look at:
:: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
:: NT\CurrentVersion\NetworkCards\1
:: Value Name : ServiceName
:: Sometimes the Network Card can be \2 or another number.


:: %2 should be the IP Address Requiring 15 digits:
:: ie. 192.168.000.002
:: If you do not use that format, it will mess up everything
:: The +30 below is to convert Decimal into Hex for the
:: ASCII values stored in the registry (REG_MULTI_SZ)

:: Run this batch file
:: c:\ip.cmd MDGMPORT1 192.168.000.002

@echo off
set NETCARDNAME=%1
set IPAddress=%2

echo REGEDIT4 > %temp%\tcpipreg.reg
::echo >> %temp%\tcpipreg.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%NETCARDNAME%\Parameters\Tcpip] >> %temp%\tcpipreg.reg


set /a digit0=%IPAddress:~0,1%+30
set /a digit1=%IPAddress:~1,1%+30
set /a digit2=%IPAddress:~2,1%+30
set digit3=2e
set /a digit4=%IPAddress:~4,1%+30
set /a digit5=%IPAddress:~5,1%+30
set /a digit6=%IPAddress:~6,1%+30
set digit7=2e
set /a digit8=%IPAddress:~8,1%+30
set /a digit9=%IPAddress:~9,1%+30
set /a digit10=%IPAddress:~10,1%+30
set digit11=2e
set /a digit12=%IPAddress:~12,1%+30
set /a digit13=%IPAddress:~13,1%+30
set /a digit14=%IPAddress:~14,1%+30


set longhexstring=%digit0%,%digit1%,%digit2%,%digit3%,%digit4%,%digit5%,%digit6%,%digit7%,%digit8%,%digit9%,%digit10%,%digit11%,%digit12%,%digit13%,%digit14%

echo "IPAddress"=hex(7):%longhexstring%,00,00 >> %temp%\tcpipreg.reg

regedit /s %temp%\tcpipreg.reg
 
You have to install the DHCP on your Server. Then set up a scope of addresses that you want the server to hand out. Excluded the machines that need static IP addresses. You can also set up the DNS, WINS, and GATEWAY address you want handed out. Then on the user machines.. just set it to USE DHCP
 
Sorry about the bonehead question...Not quite sure what I was thinking when I asked ...
 
:-( DanielMc The batch file didn't quite work on my NT40 workstation, any suggestions?
 
Hello Amadi,

Have you checked the registry using Regedit or Regedt32?
Can you verify several things for me:

You got the value of NETCARDNAME from:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1

Using the Network Card Name check that this key exists: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%NETCARDNAME%\Parameters\Tcpip]


The IP address you are using looks like this:
###.###.###.###

Please tell me the command you are using to launch this batch file.

Thank you,
Daniel
 
Hello Daniel,

i realised later that i had to reboot my system for the new address to take effect. this is something i hoped to avoid as i wanted to interface two systems on different networks. currently i run a first program, manually change the address, then run a second program, and manaully revert the address. rather sloppy.

thanks anyway.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top