Jump to content

How to change ip address on a network card ?


Recommended Posts

Hello all,

I hope i make a post in the good place ...

I'm completely new to Autoit and I would like to make a script to change ip address of a network card under windows xp.

Thank you by advance and excuse possible faults of english because in fact I'm a french guy.

Link to comment
Share on other sites

I have written a script to change the ip address to what you want. You call it with a parameter such as 'home' or 'work' etc and there is a text file which contains the details of what the address and settings are. The way I use it is I have a shortcut for each setting I want so all I have to do is click the shortcut and it's all done.

If you want it let me know. The only thing it doesn't do is set the computer name.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I have written a script to change the ip address to what you want. You call it with a parameter such as 'home' or 'work' etc and there is a text file which contains the details of what the address and settings are.  The way I use it is I have a shortcut for each setting I want so all I have to do is click the shortcut and it's all done.

If you want it let me know. The only thing it doesn't do is set the computer name.

<{POST_SNAPBACK}>

That's what I was using it for too, a simple little batchfile. One problem I could not solve, tell my pc to join a domain by means of a script, any idea?
Link to comment
Share on other sites

Tys

I am in danger of getting out of my depth soon here, but does this help?

http://www.kloth.net/services/nslookup.php

It would need a script to automate retrieving the address though.

I might have misunderstood what you want so if I have tell me in more detail.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm using AutoIt for 5 days, try this maybe helps.

AutoItSetOption("TrayIconHide", 1)

Run("RUNDLL32 SHELL32.DLL,Control_RunDLL ncpa.cpl")

WinWaitActive("Network Connections")

Send("l")

Send("!fr")

WinWaitActive("Local Area Connection Properties")

WinClose("Network Connections")

Send("i")

Send("!r")

WinWaitActive("Internet Protocol (TCP/IP) Properties")

ControlCommand("Internet Protocol (TCP/IP) Properties", "", "U&se the following IP address:", "Check", "")

Send("{TAB}")

Send("123123123123")  ;IP address to change

Send("{TAB}")

Send("{ENTER}")

WinWaitClose("Internet Protocol (TCP/IP) Properties")

ControlCommand("Local Area Connection Properties", "", "Close", "Check", "")

WinWaitClose("Local Area Connection Properties")

SplashTextOn("", "TCP/IP address changed", 278, 25, -1, -1, 1, "BigDots", 16)

Sleep(1500)

SplashOff()

Link to comment
Share on other sites

"That's what I was using it for too, a simple little batchfile. One problem I could not solve, tell my pc to join a domain by means of a script, any idea?"

I think there's a free command line utility called netdom that you can automate with an AutoIt script. I just can't remember where I got it from. Try it.

:lmao:

Link to comment
Share on other sites

netsh

netsh inter ip set address help

examples:

netsh inter ip set address "Local Area Connection" static 192.168.0.3 255.255.255.0 192.168.0.1 1

netsh inter ip set address "Local Area Connection" static <ip address> <mask> <gateway> <metric>

netsh inter ip set address "Local Area Connection" source=dhcp

netsh inter ip set dns "Local Area Connection" static 192.168.0.254

netsh inter ip add dns "Local Area Connection" 192.168.0.253 index=2

hope that helps

Link to comment
Share on other sites

That possibility would really interest me too

so if you've got a solution, it would be great ;-)

Thanks

<{POST_SNAPBACK}>

If the workstation is not part of a domain, you aparantly can change to computername and account by changing some registry settings, according to this wsh-script:

sNewName = "put new name here"

Set oShell = CreateObject ("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
  .RegDelete sTcpipParamsRegPath & "Hostname"
  .RegDelete sTcpipParamsRegPath & "NV Hostname"

  .RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
  .RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
  .RegWrite sTcpipParamsRegPath & "Hostname", sNewName
  .RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With   ' oShell

MsgBox "Computer name changed, please reboot your computer"

Damn long link

This would - if it works - be scriptable via Autoit.

!! Beware, I did not test that, it back up your data before;) !!

hth, Tys

Link to comment
Share on other sites

  • 4 months later...

I have a training lab that changes between the xxx.xxx.3.xxx and the 10.0.0.0 network. Here is how it is handled other than physically moving the ehternet cable:

@echo off

:Note: set current IP Address, netID-1,2,3 octet and CompID- last octet

FOR /F "skip=2 tokens=2 delims=[]" %%a in ('nbtstat -s') do set ip=%%a

FOR /F "tokens=1,2,3,4,5 delims=.=" %%a in ('set ip') do @set netID=%%b.%%c.%%d & set compID=%%e

Echo Current IP address: %IP%

Echo Current Network: %netID%

Echo Current Computer Number: %compID%

if %netID% == 10.1.1 (

goto setNet162

) else (

goto setNet10

)

goto end

:setNet10

set /p yn="Would you like to change to the 10.1.1 network?(Y,N)"

IF NOT "%yn%" == "y" goto end

REM response is case sensitive

Echo Changing IP address to 10.1.1.%compID%

netsh interface ip set address local static 10.1.1.%compID% 255.255.255.0 10.1.1.254 1

if not %errorlevel% == 0 then Echo ERROR

netsh interface ip set dns local static 162.29.224.90 primary

if not %errorlevel% == 0 then Echo ERROR

ping 10.1.1.100

REGEDIT -S Printers\HP10Net.reg

goto end

:setNet162

set /p yn="Would you like to change to the 162.29.3 network?(Y,N)"

IF NOT "%yn%" == "y" goto end

REM response is case sensitive

Echo Changing IP address to 162.29.3.%compID%

netsh interface ip set address local static 162.29.3.%compID% 255.255.255.0 162.29.3.254 1

if not %errorlevel% == 0 then Echo ERROR

netsh interface ip set dns local static 162.29.224.90 primary

if not %errorlevel% == 0 then Echo ERROR

ping google.com

REGEDIT -S Printers\HP3Net.reg

goto end

:end

ipconfig

pause

---------------------------------------END-SwitchIP.bat------------------------------------

In the script I run the reg key to change the default printer. I've installed the same printer twice, once for each network. The reg key just sets the appropriate printer to be the default. Here is one of the reg key's:

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows]

"Device"="HP LaserJet 4 (3 Network),winspool,Ne00:"

-----------------------------------------------------------------------------------------------

The last thing we did was to script telnetting to the printer while on the same network to change it's address to the other network. Here is the .au3 script:

This can vary depending on the printer. The one used here is a HP LaserJet 4

; Script Start

if $CmdLine[0] < 2 then

$oldIP = InputBox("Old IP Address", "What is the Old Printer IP Address?", "162.29.", "")

$newIP = InputBox("New IP Address", "What is the New Printer IP Address?", "10.1.", "")

else

$oldIP = $CmdLine[1]

$newIP = $CmdLine[2]

EndIf

$test = StringSplit( $oldIP, "." )

if $test[0] <> 4 then

msgbox(0, "Error", "Error: invalid old IP Address '" & $oldIP & "'")

exit

endif

$test = StringSplit ( $newIP, "." )

if $test[0] <> 4 then

msgbox(0, "Error", "Error: invalid new IP Address'" & $newIP & "'")

exit

endif

$newGW = $test[1] & "." & $test[2] & "." & $test[3] & ".254"

BlockInput(1)

Run("cmd")

sleep("1000")

send("echo off{ENTER}")

send("cls{ENTER}")

send("telnet "& $oldIP & "{ENTER}")

sleep("1000")

send("<PASSWORD>{ENTER}")

sleep("1000")

send("ip:"& $newIP & "{ENTER}")

sleep("1000")

send("default-gw:"& $newGW & "{ENTER}")

sleep("1000")

send("/" & "{ENTER}")

sleep("1000")

send("{ENTER}quit" & "{ENTER}")

sleep("1000")

send("Update complete, Window will close in 5 seconds")

sleep("5000")

send("{ENTER}exit" & "{ENTER}")

BlockInput(0)

--------------------------------END-SwitchPrinterIP.exe-----------------------------------

Enjoy.

Link to comment
Share on other sites

  • 5 months later...

I was working on something today and the information on netsh ubove helped me alot.

here is my ip change gui and source if anyone want to look at it

http://home.electronicinsanity.com/ei/auto.../ipset.rar/view

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

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
 Share

  • Recently Browsing   0 members

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