Solved

Script that releases and renew a ip address with a script.

Posted on 2007-12-06
2
2,394 Views
Last Modified: 2011-09-20
Hi,

I got this script from EE> which can release and renew ip address once run.
What my issue is.
In remote locations when its required to change the ip address after reserving the ip in the DHCP.I need to release and renew it.
After a release when connected online i cannot connect to renew.So i need a script that can first release and then renew it.

@echo off
::
:: IPREPAIR.CMD - Attempt to repair the network connections
::
:: Written 12/16/03 by Rick Campbell
::

:: Determine what OS this script is running on.
if not "%OS%"=="Windows_NT" goto :end
ver | find "[Version 5" || goto :end

:: Clear environment variables
set dhcp=

:: Determine if client is dynamically or statically assigned an IP address
echo Determining if client is DHCP based...
for /f "tokens=3 delims= " %%d in (
    ''netsh int ip sh add ^| find /i "DHCP"''
) do (
    set dhcp=%%d
)

:: If client is dynamic, then release and renew the IP address
if /i "%dhcp%"=="Yes" (
    echo Client is using DHCP - Renewing the DHCP Address lease...
    ipconfig /release > nul
    ipconfig /renew   > nul
) else (
    echo Client is statically assigned - leaving address untouched...
)

:: Flush the ARP, NetBIOS, and DNS cache''s
echo Flushing the ARP Cache...
arp -d * > nul
echo Flushing the NetBIOS Cache...
nbtstat -R > nul
echo Flushing the DNS Cache...
ipconfig /flushdns > nul

:: Re-register the NetBIOS and Computer names with WINS and DNS
echo Re-registering the NetBIOS and Computer name with WINS and DNS...
nbtstat -RR > nul
ipconfig /registerdns > nul

goto :eof

:END
echo This script is to be run on Windows 2000/XP/2003 Only!

Can you help checking if this script is right.

Regards
Sharath
0
Comment
Question by:bsharath
2 Comments
 
LVL 26

Accepted Solution

by:
farhankazi earned 500 total points
ID: 20426715
Hi Sharath,
Above script should work perfectly. Do you receive any error?

Only following lines should be replaced...

>>for /f "tokens=3 delims= " %%d in (
>>    ''netsh int ip sh add ^| find /i "DHCP"''

with:

for /f "tokens=3 delims= " %%d in ('netsh int ip sh add ^| find /i "DHCP"') do (

Hope this helps!
Farhan
0
 
LVL 11

Author Comment

by:bsharath
ID: 20491139
Hi Farhan,

Seems you are very bussy.Can you please look at my posts some questions are very urgent and no one except you can do them...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now