如果是win2k/xp就可以。执行netsh interface 命令。下面是一个例子。
//form文件:
object FrmChangeIp: TFrmChangeIp
Left = 232
Top = 194
BorderIcons = []
BorderStyle = bsSingle
Caption = '动态改变IP'
ClientHeight = 186
ClientWidth = 256
Color = clBtnFace
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 12
object Label1: TLabel
Left = 48
Top = 48
Width = 36
Height = 12
Caption = 'IP地址'
end
object Label2: TLabel
Left = 48
Top = 80
Width = 24
Height = 12
Caption = '掩码'
end
object Label3: TLabel
Left = 48
Top = 112
Width = 24
Height = 12
Caption = '网关'
end
object Label5: TLabel
Left = 41
Top = 19
Width = 48
Height = 12
Caption = '连接名称'
end
object Edit1: TEdit
Left = 104
Top = 16
Width = 121
Height = 20
TabOrder = 0
Text = '本地连接'
end
object Edit2: TEdit
Left = 104
Top = 48
Width = 121
Height = 20
TabOrder = 1
Text = '192.168.0.30'
end
object Edit3: TEdit
Left = 104
Top = 80
Width = 121
Height = 20
TabOrder = 2
Text = '255.255.255.0'
end
object Edit4: TEdit
Left = 104
Top = 112
Width = 121
Height = 20
TabOrder = 3
Text = '192.168.0.1'
end
end
//执行代码
procedure TFrmChangeIp.BtnChangeClick(Sender: TObject);
var
str:string;
begin
str:='netsh interface ip set address '+edit1.text +' static '+edit2.text+' '+edit3.text+' '+edit4.text+' 1';
winexec(PChar(str),sw_hide);
end;