如何编程更改IP?

pharaoh 2002-06-18 08:45:33
我有一台电脑需要在两个固定的IP切换,如何编程实现,或者有Windows命令可以实现?
...全文
398 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
naughtyboy 2002-06-30
  • 打赏
  • 举报
回复
我这里有一段程序
unit Unit1;

interface

uses
Windows, Messages, Classes, Forms, Controls, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
IPAddress: TBevel;
SetIP: TButton;
ClearIP: TButton;
procedure FormCreate(Sender: TObject);
procedure SetIPClick(Sender: TObject);
procedure ClearIPClick(Sender: TObject);
private
FIPAddress: Longint;
HIPAddress: HWND;
PrevWndProc: TWndMethod;
procedure NewWindowProc(var Message: TMessage);
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
CommCtrl;

const
IP_ADDRESS_ID: Longword = $0100;

procedure TForm1.FormCreate(Sender: TObject);
var
lpInitCtrls: TInitCommonControlsEx;
begin
lpInitCtrls.dwSize := SizeOf(TInitCommonControlsEx);
lpInitCtrls.dwICC := ICC_INTERNET_CLASSES;
if InitCommonControlsEx(lpInitCtrls) then
begin
PrevWndProc := WindowProc;
WindowProc := NewWindowProc;

HIPAddress := CreateWindowEx(WS_EX_LEFT, WC_IPADDRESS, nil,
WS_CHILD + WS_VISIBLE + WS_BORDER + WS_TABSTOP,
IPAddress.Left, IPAddress.Top, IPAddress.Width, IPAddress.Height,
Handle, IP_ADDRESS_ID, HInstance, nil);
SendMessage(HIPAddress, IPM_SETFOCUS, 0, 0);
end;
end;

procedure TForm1.NewWindowProc(var Message: TMessage);
var
nField: longint;
begin
case Message.Msg of
WM_NOTIFY:
begin
if PNMHDR(Ptr(Message.lParam)).idFrom = IP_ADDRESS_ID then
begin
case PNMIPAddress(ptr(Message.lParam)).hdr.code of
IPN_FIELDCHANGED:
begin
if SendMessage(HIPAddress, IPM_ISBLANK, 0, 0) = 0 then
SendMessage(HIPAddress, IPM_GETADDRESS, 0, lParam(LPDWORD(@FIPAddress)));
end;
end;
end;
end;
WM_COMMAND:
begin
if Message.WParamLo = IP_ADDRESS_ID then
case Message.WParamHi of
EN_SETFOCUS:
begin
nField := SendMessage(HIPAddress, IPM_GETADDRESS, 0,
lParam(LPDWORD(@FIPAddress)));
if nField = 4 then nField := 0;
SendMessage(HIPAddress, IPM_SETFOCUS, wParam(nField), 0);
end;
EN_KILLFOCUS:
begin
if SendMessage(HIPAddress, IPM_ISBLANK, 0, 0) = 0 then
SendMessage(HIPAddress, IPM_GETADDRESS, 0, lParam(LPDWORD(@FIPAddress)));
end;
EN_CHANGE:
begin
end;
end;
end;
end;
if Assigned(PrevWndProc) then PrevWndproc(Message);
end;

procedure TForm1.SetIPClick(Sender: TObject);
begin
FIPAddress := MAKEIPADDRESS(127, 0, 0, 1);
SendMessage(HIPAddress, IPM_SETADDRESS, 0, lParam(DWORD(FIPAddress)));
end;

procedure TForm1.ClearIPClick(Sender: TObject);
begin
SendMessage(HIPAddress, IPM_CLEARADDRESS, 0, 0);
end;

end.
Billy_Chen28 2002-06-19
  • 打赏
  • 举报
回复
可以用一条shell命令:
netsh interface ip set address local static 192.168.0.1 255.255.255.0 192.168.0.10 1
我真的是大海 2002-06-19
  • 打赏
  • 举报
回复
gz too
benny87 2002-06-19
  • 打赏
  • 举报
回复

这也是我一个未解决的问题
gz
dongdong_daddy 2002-06-19
  • 打赏
  • 举报
回复
I have no idear.

5,527

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧