AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IP change

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
DeWild1



Joined: 30 Apr 2006
Posts: 169
Location: Shigle Springs

PostPosted: Fri Jan 18, 2008 12:26 am    Post subject: IP change Reply with quote

Hi, is there any automated way to change the IP of network card? Then change it back to DHCP?
I am looking at the reg now, but I think the problem will be determining what one is the default, (active), network card.
_________________
CPULOCK.com
virusSWAT.com
GuaranteedPCFIX.com
911PCFIX.com
Back to top
View user's profile Send private message Visit poster's website
jaco0646



Joined: 07 Oct 2006
Posts: 553
Location: MN, USA

PostPosted: Fri Jan 18, 2008 2:36 am    Post subject: Reply with quote

I wrote a script to do this on my laptop by using the netsh command; however, I just entered the name of the network connection manually into the script. I don't know if there's a command to return that value or not, but I expect there is. I just needed something simple at the time. By modifying it a bit, it might do what you need, or at least give you some ideas.

>DOWNLOAD<
_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
aCkRiTe



Joined: 21 Jul 2006
Posts: 502

PostPosted: Fri Jan 18, 2008 3:47 am    Post subject: Reply with quote

I started to make a script for this a while back, but I dont think I ever completed it. If I remember correctly there are a few things that still need to be worked on in the following script, but I dont plan on working on it any time soon. Feel free to take a look at it and tinker with it as need be.

Code:

#SingleInstance Force
#Persistent
#NoEnv
Process Priority, , High
SetBatchLines, -1
Menu, Tray, Icon, Shell32.dll, 89
Able = Disable
SetWorkingDir, %A_Temp%   
FileDelete, NetChange.tmp
FileDelete, NetChange1.tmp
FileDelete, NetChange.bat
RunWait, %Comspec% /c netsh interface show interface >>NetChange.tmp, , Hide
Loop, Read, NetChange.tmp
   {
      StringReplace, Delimiter, A_LoopReadLine, Dedicated, §, UseErrorLevel
      If ErrorLevel = 0
         Continue
      Loop, Parse, Delimiter, §
         {
            If A_LoopField not contains able
               {
                  StringReplace, LAN_Name, A_LoopField, %A_Space%%A_Space%, , All
                  FileAppend, %LAN_Name%|, NetChange1.tmp
                  LAN_Cnt++
               }
         }
   }
FileDelete, NetChange.tmp
FileRead, Var, NetChange1.tmp
StringTrimRight, Var, Var, 1
FileAppend, %Var%, NetChange.tmp
FileRead, LAN, NetChange.tmp



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



ICCE_size             := 8
GWL_HINSTANCE         := -6
WM_USER               := 0x400
ICC_INTERNET_CLASSES    := 0x800
WS_CHILD              := 0x40000000
WS_VISIBLE            := 0x10000000
IPM_GETADDRESS        := WM_USER + 102
IPM_SETADDRESS        := WM_USER + 101



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Gui +LastFound
GuiID := WinExist()
Gui, Font, cBlue
Gui, Color, Black
Gui, Font, s10
Gui, Add, GroupBox, x15 y15 w293 h320, Internet Protocol (TCP/IP) Settings
Gui, Font, cLime
Gui, Add, Text, x25 y49 w70 h20, LAN Name:
Gui, Add, DropDownList, Choose1 R%LAN_Cnt% vLAN_Name gLAN_Name x95 y45 w202 h25, %LAN%
Gui, Add, Checkbox, x25 y85 gDHCP vDHCP, DHCP (Obtain an IP address automatically)
Gui, Add, Text, x25 y122 w100 h20, IP Address:
IP_Address := GuiAddIPAddress(GuiID, 146, 120, 150, 20)
Gui, Add, Text, x25 y153 w100 h20, Subnet Mask:
Subnet_Mask := GuiAddIPAddress(GuiID, 146, 150, 150, 20)
Gui, Add, Text, x25 y183 w120 h20, Default Gateway:
Default_Gateway := GuiAddIPAddress(GuiID, 146, 180, 150, 20)
Gui, Add, Text, x25 y213 w120 h20, Preferred DNS:
Preferred_DNS := GuiAddIPAddress(GuiID, 146, 210, 150, 20)
Gui, Add, Text, x25 y243 w120 h20, Alternate DNS:
Alternate_DNS := GuiAddIPAddress(GuiID, 146, 240, 150, 20)
Gui, Add, Text, x25 y273 w120 h20, Preferred WINS:
Preferred_WINS := GuiAddIPAddress(GuiID, 146, 270, 150, 20)
Gui, Add, Text, x25 y303 w120 h20, Alternate WINS:
Alternate_WINS := GuiAddIPAddress(GuiID, 146, 300, 150, 20)
Gui, Add, Picture, x15 y351 Icon89, C:\WINDOWS\system32\SHELL32.dll
Gui, Add, Picture, x278 y351 Icon89, C:\WINDOWS\system32\SHELL32.dll
Gui, Font, s16
Gui, Add, Button, x62 y348 w200 h35 Default vButton, APPLY
;GuiControl, Disable, Button
Gui, Show, Center h395 w325, NetChange
Return



LAN_Name:
Gui, Submit, NoHide
GuiControlGet, LAN_Name, , ComboBox1
IfExist, %A_WinDir%\NetChange.ini
      FileRead, INI_Content, %A_WinDir%\NetChange.ini
Else
      Return
IfInString, INI_Content, [%LAN_Name%]
      {
            IniRead, IP_Address_1, %A_WinDir%\NetChange.ini, %LAN_Name%, IP_Address
            IniRead, Subnet_Mask_1, %A_WinDir%\NetChange.ini, %LAN_Name%, Subnet_Mask
            IniRead, Default_Gateway_1, %A_WinDir%\NetChange.ini, %LAN_Name%, Default_Gateway
            IniRead, Preferred_DNS_1, %A_WinDir%\NetChange.ini, %LAN_Name%, Preferred_DNS
            IniRead, Alternate_DNS_1, %A_WinDir%\NetChange.ini, %LAN_Name%, Alternate_DNS
            IniRead, Preferred_WINS_1, %A_WinDir%\NetChange.ini, %LAN_Name%, Preferred_WINS
            IniRead, Alternate_WINS_1, %A_WinDir%\NetChange.ini, %LAN_Name%, Alternate_WINS
            IPAddress_SetAddress(IP_Address, IP_Address_1)
            IPAddress_SetAddress(Subnet_Mask, Subnet_Mask_1)
            IPAddress_SetAddress(Default_Gateway, Default_Gateway_1)
            IPAddress_SetAddress(Preferred_DNS, Preferred_DNS_1)
            IPAddress_SetAddress(Alternate_DNS, Alternate_DNS_1)
            IPAddress_SetAddress(Preferred_WINS, Preferred_WINS_1)
            IPAddress_SetAddress(Alternate_WINS, Alternate_WINS_1)
      }
Else
      {
            IPAddress_ClearAddress(IP_Address)
            IPAddress_ClearAddress(Subnet_Mask)
            IPAddress_ClearAddress(Default_Gateway)
            IPAddress_ClearAddress(Preferred_DNS)
            IPAddress_ClearAddress(Alternate_DNS)
            IPAddress_ClearAddress(Preferred_WINS)
            IPAddress_ClearAddress(Alternate_WINS)
      }
Return



DHCP:
Loop, 7
      Control %Able%, , SysIPAddress32%A_Index%, ahk_id %GuiID%
If Able = Disable
      Able = Enable
Else
      Able = Disable
Return



ButtonApply:
Gui, Submit, NoHide
IPAddress := GuiControlGetIPAddress(IP_Address)
;GuiControlGetIPAddress(IP_Address)
;IP_Address = %Var%
GuiControlGetIPAddress(Subnet_Mask)
Subnet_Mask = %Var%
GuiControlGetIPAddress(Default_Gateway)
Default_Gateway = %Var%
GuiControlGetIPAddress(Preferred_DNS)
Preferred_DNS = %Var%
GuiControlGetIPAddress(Alternate_DNS)
Alternate_DNS = %Var%
GuiControlGetIPAddress(Preferred_WINS)
Preferred_WINS = %Var%
GuiControlGetIPAddress(Alternate_WINS)
Alternate_WINS = %Var%



;**************************************************************************************************
Msgbox, IP Address - %IPAddress%`nSubnet Mask - %Subnet_Mask%`nDefault Gateway - %Default_Gateway%
Return
;**************************************************************************************************



GuiControl, Hide, Button

If DHCP = 1
   {
            FileAppend,
            ( LTrim
            netsh interface ip set address "%LAN_Name%" dhcp
            netsh interface ip set dns "%LAN_Name%" dhcp
            netsh interface ip set wins "%LAN_Name%" dhcp
      echo>>NetChange2.tmp
            ), NetChange.bat
      Goto, End
      }
If DHCP = 0
      {
            FileAppend,
            ( LTrim
            netsh interface ip set address "%LAN_Name%" static %IP_Address% %Subnet_Mask% %Default_Gateway% 1   
            netsh interface ip set dns "%LAN_Name%" static %Preferred_DNS%
            netsh interface ip set wins "%LAN_Name%" static %Preferred_WINS%
            netsh interface ip add dns "%LAN_Name%" %Alternate_DNS% index=2
            netsh interface ip add wins "%LAN_Name%" %Alternate_WINS% index=2
      echo>>NetChange2.tmp
            ), NetChange.bat
            IniWrite, %IP_Address%, %A_WinDir%\NetChange.ini, %LAN_Name%, IP_Address
            IniWrite, %Subnet_Mask%, %A_WinDir%\NetChange.ini, %LAN_Name%, Subnet_Mask
            IniWrite, %Default_Gateway%, %A_WinDir%\NetChange.ini, %LAN_Name%, Default_Gateway
            IniWrite, %Preferred_DNS%, %A_WinDir%\NetChange.ini, %LAN_Name%, Preferred_DNS
            IniWrite, %Alternate_DNS%, %A_WinDir%\NetChange.ini, %LAN_Name%, Alternate_DNS
            IniWrite, %Preferred_WINS%, %A_WinDir%\NetChange.ini, %LAN_Name%, Preferred_WINS
            IniWrite, %Alternate_WINS%, %A_WinDir%\NetChange.ini, %LAN_Name%, Alternate_WINS
      Goto, End
      }
Return



End:
;Run, NetChange.bat, , Hide
Gui, Font, s12 Bold
Gui, Add, Text, x65 y355 cRed vText w200 h40, Applying Changes
Gui, Submit, NoHide
Sleep, 500
Loop:
Progress = Applying Changes
Loop
   {
      If A_Index = 2
         Progress = Applying Changes.
      If A_Index = 3
         Progress = Applying Changes. .
      If A_Index = 4
         Progress = Applying Changes. . .
      If A_Index = 5
         Progress = Applying Changes. . . .
      If A_Index = 6
         Progress = Applying Changes. . . . .
      If A_Index = 7
         Progress = Applying Changes. . . . . .
      GuiControl, , Static11, %Progress%
      IfExist, NetChange2.tmp
         Break
      Sleep, 500
      If A_Index = 7
         Goto, Loop
   }
Gui, Font, s14 cRed Bold
GuiControl, Font, Text
GuiControl, Move, Text, x70 y355
GuiControl, , Static11, Changes Complete!
Return

GuiClose:
FileDelete, NetChange.tmp
FileDelete, NetChange1.tmp
FileDelete, NetChange2.tmp
FileDelete, NetChange.bat
ExitApp



GuiAddIPAddress(_guiHwnd, _x, _y, _w, _h)
   {
         local hInstance, structICCE, ipaHwnd, ipaInstance
         local msg
         hInstance := DllCall("GetWindowLong"
                  , "UInt", _guiHwnd
                  , "Int", GWL_HINSTANCE)
         VarSetCapacity(structICCE, ICCE_size)
            SetNextUInt(structICCE, ICCE_size, true)
            SetNextUInt(structICCE, ICC_INTERNET_CLASSES)
            DllCall("InitCommonControlsEx", "UInt", &structICCE)
         ipaHwnd := DLLCall("CreateWindowEx"
                  , "UInt", 0                     
                  , "Str", "SysIPAddress32"       
                  , "UInt", 0                   
                  , "UInt", WS_CHILD | WS_VISIBLE
                  , "Int", _x                     
                  , "Int", _y                     
                  , "Int", _w                     
                  , "Int", _h                     
                  , "UInt", _guiHwnd             
                  , "UInt", 0                   
                  , "UInt", hInstance           
                  , "UInt", 0)                   
            If (ErrorLevel != 0 or ipaHwnd = 0)
               {
                        msg = %msg% Cannot create IP Address control (%ErrorLevel%/%A_LastError%)
                        Gosub GuiAddIPAddressddress_CleanUp
                        Return msg
               }
         Gosub GuiAddIPAddressddress_CleanUp
         Return ipaHwnd
         GuiAddIPAddressddress_CleanUp:
         Return
   }
Return



GuiControlGetIPAddress(_ipaHwnd, mode="")
   {
            local ipAddress, a
         If (_ipaHwnd = 0)
                  Return
         binIPAddress = 0000
            SendMessage IPM_GETADDRESS, 0, &binIPAddress, , ahk_id %_ipaHwnd%
            If ErrorLevel = FAIL
                  Return
            a := &binIPAddress
         If (SubStr(mode, 1, 1) = "i")
                  Return *a + (*(a + 1) << 8) +  (*(a + 2) << 16) + (*(a + 3) << 24)
            Else   
                  Var := *(a + 3) . "." . *(a + 2) . "." . *(a + 1) . "." . *a
   }
Return



 
IPAddress_SetAddress(_ipaHwnd, _ipAddress)
   {
         local binIPAddress
         If (_ipaHwnd = 0)
                  Return
         binIPAddress := 0
            Loop, Parse, _ipAddress, .
               {
                     binIPAddress |= A_LoopField << 8*(4 - A_Index)
               }
         SendMessage, IPM_SETADDRESS, 0, binIPAddress, , ahk_id %_ipaHwnd%
   }
Return



IPAddress_ClearAddress(_ipaHwnd)
   {
         SendMessage 1124, 0, 0, , ahk_id %_ipaHwnd%
   }
Return



SetNextUInt(ByRef @struct, _value, _bReset=false)
   {
            local addr
            static $offset
         If (_bReset)
               {
                     $offset := 0
               }
            addr := &@struct + $offset
            $offset += 4
            DllCall("RtlFillMemory", "UInt", addr,     "UInt", 1, "UChar", (_value & 0x000000FF))
            DllCall("RtlFillMemory", "UInt", addr + 1, "UInt", 1, "UChar", (_value & 0x0000FF00) >> 8)
            DllCall("RtlFillMemory", "UInt", addr + 2, "UInt", 1, "UChar", (_value & 0x00FF0000) >> 16)
            DllCall("RtlFillMemory", "UInt", addr + 3, "UInt", 1, "UChar", (_value & 0xFF000000) >> 24)
   }
Return

_________________

HTH...

Back to top
View user's profile Send private message
DeWild1



Joined: 30 Apr 2006
Posts: 169
Location: Shigle Springs

PostPosted: Fri Jan 18, 2008 10:35 pm    Post subject: Reply with quote

aCkRiTe, Please do not tell me you just made that! Mad
I will be jealous and angry that God did not bless me with your talents! Holly cow..

On Vista, got this,


Have not tried on XP yet, but dang! Looks like some really interesting code.

jaco0646,
I will try your code now.
Thank you both. The other tools on the Net did not work.
Via your code, I should be able figure it out and script it for my needs for my techs and different networks.
_________________
CPULOCK.com
virusSWAT.com
GuaranteedPCFIX.com
911PCFIX.com
Back to top
View user's profile Send private message Visit poster's website
DeWild1



Joined: 30 Apr 2006
Posts: 169
Location: Shigle Springs

PostPosted: Fri Jan 18, 2008 10:53 pm    Post subject: Reply with quote

aCkRiTe, I am sure the problem is something simple, but may I suggest you SELL it! Cool
It is very pretty and cool.
If you add profiles and groups like other apps I have seen, you should really sell it!

jaco0646;
Exactly what I was looking for! I spent 1/2 of yesterday reading forums and trying to figure it out, the other half looking for a third party app that would do it, (an app for $60 was the only one I found that came close on Softpedia.com), and most of this morning trying to fix the problems that came from trying to use all the third party apps.. (Dam Vista) Evil or Very Mad

I can read it and modify it as I need.
Thank you. It works perfect!
_________________
CPULOCK.com
virusSWAT.com
GuaranteedPCFIX.com
911PCFIX.com
Back to top
View user's profile Send private message Visit poster's website
aCkRiTe



Joined: 21 Jul 2006
Posts: 502

PostPosted: Fri Jan 18, 2008 11:15 pm    Post subject: Reply with quote

DeWild1 wrote:
aCkRiTe, I am sure the problem is something simple, but may I suggest you SELL it! Cool
It is very pretty and cool.
If you add profiles and groups like other apps I have seen, you should really sell it!


Well thank you. Like I said I started the script a while back and cant remember if its a completed product(I dont think it is). I received a lot of help from PhiLho with this script. You can do with it as you please. I might one day finish it up and post it in the scripts and functions section, but Ive been a little busy and havent been around the forum lately, I stop by every once in a while though. By the way I got the idea from here - http://www.lyrasoftware.com There is a free netchange download there that might be of interest to you. I just wanted to see if I could do it with AHK.
_________________

HTH...

Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Fri Jan 18, 2008 11:36 pm    Post subject: Reply with quote

there are also Yahoo Widgets to do the same thing. (free $, not lightweight though)
_________________
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 553
Location: MN, USA

PostPosted: Wed Jan 23, 2008 3:05 am    Post subject: Reply with quote

DeWild1, I just noticed that the systeminfo command returns the status of network cards. It may be useful in your script.

EDIT: The ipconfig command gives this info as well.
_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group