Russian Qt Forum
Май 12, 2024, 18:29 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: [1]   Вниз
  Печать  
Автор Тема: Как программно изменить IP адрес  (Прочитано 29864 раз)
SiBear
Гость
« : Март 19, 2004, 15:09 »

Может кто знает как можно программно (либо через .cmd батник) изменить IP адрес/gateway на локальном компьютере? Главное, чтобы это работало через коммандную строку.

Пока выхожу из положения: есть 2 .reg файла. В одном прописаны настройки для первого IP, во втором для 2-го. Изменение IP адреса происходит следующим образом: щелкаю по 1-му .reg файлу (данные копируются в реестр). После этого щелкаю по "двум мониторам" в трее и выбираю Disable. Затем правая кнопка мышки по "Local Area Connection" и "Enable".

Надо как-то автоматизировать этот процесс. Сам программист, поэтому могу написать утилиту самостоятельно, знать бы как.
Записан
Anonymous
Гость
« Ответ #1 : Ноябрь 20, 2004, 00:12 »

Цитата: "SiBear"
Может кто знает как можно программно (либо через .cmd батник) изменить IP адрес/gateway на локальном компьютере? Главное, чтобы это работало через коммандную строку.

Пока выхожу из положения: есть 2 .reg файла. В одном прописаны настройки для первого IP, во втором для 2-го. Изменение IP адреса происходит следующим образом: щелкаю по 1-му .reg файлу (данные копируются в реестр). После этого щелкаю по "двум мониторам" в трее и выбираю Disable. Затем правая кнопка мышки по "Local Area Connection" и "Enable".

Надо как-то автоматизировать этот процесс. Сам программист, поэтому могу написать утилиту самостоятельно, знать бы как.
Записан
Борис
Гость
« Ответ #2 : Январь 11, 2005, 14:23 »

Цитата: "SiBear"
Может кто знает как можно программно (либо через .cmd батник) изменить IP адрес/gateway на локальном компьютере? Главное, чтобы это работало через коммандную строку.

Пока выхожу из положения: есть 2 .reg файла. В одном прописаны настройки для первого IP, во втором для 2-го. Изменение IP адреса происходит следующим образом: щелкаю по 1-му .reg файлу (данные копируются в реестр). После этого щелкаю по "двум мониторам" в трее и выбираю Disable. Затем правая кнопка мышки по "Local Area Connection" и "Enable".

Надо как-то автоматизировать этот процесс. Сам программист, поэтому могу написать утилиту самостоятельно, знать бы как.

 мне тоже это интеоесно! нельзя ли мне хотя бы эти два .reg выслать по e-m@il kbekde[at]bk.ru?
Записан
Anonymous
Гость
« Ответ #3 : Февраль 17, 2005, 20:27 »

Цитата: "SiBear"
Может кто знает как можно программно (либо через .cmd батник) изменить IP адрес/gateway на локальном компьютере? Главное, чтобы это работало через коммандную строку.

Пока выхожу из положения: есть 2 .reg файла. В одном прописаны настройки для первого IP, во втором для 2-го. Изменение IP адреса происходит следующим образом: щелкаю по 1-му .reg файлу (данные копируются в реестр). После этого щелкаю по "двум мониторам" в трее и выбираю Disable. Затем правая кнопка мышки по "Local Area Connection" и "Enable".

Надо как-то автоматизировать этот процесс. Сам программист, поэтому могу написать утилиту самостоятельно, знать бы как.


А если можешь вышли и мне эти bat- файлы   u3_dimedrol@mail.ru
Записан
Simon Logic
Гость
« Ответ #4 : Октябрь 07, 2005, 15:17 »

После махинаций с реестром попробуй выполнить через ShellExecute (или любая другая альтернатива)
Код:
ipconfig /renew

От себя: просьба выложить содержимое .reg файлов прямо в форум.
Записан
mxdev
Гость
« Ответ #5 : Ноябрь 09, 2005, 15:50 »

Changing TCP/IP settings via the GUI is tedious at best. It's accomplished more easily with a little VB scripting magic.

Changing a machine's TCP/IP settings from the GUI usually involves a number of steps. This becomes tedious if you have to do it often—for example, if the machine is part of a testbed network where you test different deployment scenarios. Using the VBScript in this hack, you can quickly and frequently modify the network adapter information on a computer.

The Code
To use this script, type it into Notepad (with Word Wrap turned off) and save it with a .vbs extension as ChangeIP.vbs:

Option Explicit



Dim NetworkAdapter, AdapterConfiguration 'Objects

Dim IPAddress, SubnetMask, Gateway, DNS 'String Arrays

Dim RetVal 'Integers



For Each NetworkAdapter In

GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapter")

If NetworkAdapter.AdapterType = "Ethernet 802.3" Then

For Each AdapterConfiguration In GetObject("winmgmts:").InstancesOf

("Win32_NetworkAdapterConfiguration")

If UCase(AdapterConfiguration.ServiceName) = UCase(NetworkAdapter.ServiceName) Then

IPAddress = Array("192.168.0.10")

SubnetMask = Array("255.255.255.0")

Gateway = Array("192.168.0.1")

DNS = Array("35.8.2.41")



RetVal = AdapterConfiguration.EnableStatic(IPAddress, SubnetMask)

If Not RetVal = 0 Then

WScript.Echo "Failure assigning IP/Subnetmask."

End If

RetVal = AdapterConfiguration.SetGateways(Gateway)

If Not RetVal = 0 Then

WScript.Echo "Failure assigning Gateway."

End If

RetVal = AdapterConfiguration.SetDnsServerSearchOrder(DNS)

If Not RetVal = 0 Then

WScript.Echo "Failure assinging DNS search order."

End If

End If

Next

End If

Next
Running the Hack
To run this hack, modify the IP information in the following lines, as required by your environment:

IPAddress = Array("192.168.0.10")

SubnetMask = Array("255.255.255.0")

Gateway = Array("192.168.0.1")

DNS = Array("35.8.2.41")
For example, to change the IP address of a machine to 172.16.44.3 with subnet mask 255.255.0.0 and default gateway 172.16.44.1, replace those lines with these:

IPAddress = Array("172.16.44.3")

SubnetMask = Array("255.255.0.0")

Gateway = Array("172.16.44.1")
Also, note this statement:

If NetworkAdapter.AdapterType = "Ethernet 802.3" Then
This is where the script checks the AdapterType, which in this script is listed as "Ethernet 802.3". You should modify this line if you have a different networking environment.

Once these changes have been made to the script, create a shortcut to the script and double-click on the shortcut to run the script.

—Rod Trent
Записан
mxdev
Гость
« Ответ #6 : Ноябрь 09, 2005, 16:00 »

Description

Sets the IP address of a computer to 192.168.1.141, and sets the IP gateway to 192.168.1.100.

Supported Platforms

Windows Server 2003 Yes
Windows XP Yes
Windows 2000 Yes
Windows NT 4.0 Yes
Windows 98 Yes

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
 
For Each objNetAdapter in colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
        WScript.Echo "The IP address has been changed."
    Else
        WScript.Echo "The IP address could not be changed."
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

http://www.microsoft.com/technet/scriptcenter/scripts/network/client/modify/nwmovb01.mspx
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.046 секунд. Запросов: 20.