• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi开发的IP地址修改工具

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

用Delphi进行开发的,直接修改注册表,需重启电脑后才生效

procedure TForm1.SpeedButton3Click(Sender: TObject);
var
  reg:TRegistry;
  IP,WG,ZY:array [0..255] of char;
  ID,CardNum:string;
  Psize:Dword;
  DNS:string;
begin
  reg:=TRegistry.Create;
  name:='';
  reg.RootKey:=HKEY_LOCAL_MACHINE;
  ID:=RGcardList.Items.Strings[RGCardList.itemindex];
  cardNum:=copy(ID,pos(';',ID)+1,length(ID));
  reg.CloseKey;
  if length(CardNum) < 2 then
    CardNum:='00'+CardNum;
  if LengTh(CardNum) < 3 then
    CardNum:='0'+CardNum;
  reg.OpenKey('SYSTEM\ControlSet'+CardNum+'\Services',false);
  reg.OpenKey('Tcpip\Parameters\Interfaces',false);
  ID:=CardIdLt.Strings[CardIDLt.IndexOf(ID)+1];
  reg.OpenKey(id,false);
  DNS:=Reg.ReadString('NameServer');
  RegqueryValueEx(reg.CurrentKey,'IPAddress',nil,nil,@IP,@Psize);
  Edit1.Text:=copy(IP,0,strlen(IP));
  RegqueryValueEx(reg.CurrentKey,'SubnetMask',nil,nil,@ZY,@Psize);
  Edit2.Text:=copy(ZY,0,strlen(ZY));
  RegqueryValueEx(reg.CurrentKey,'DefaultGateway',nil,nil,@WG,@Psize);
  Edit3.Text:=copy(WG,0,strlen(WG));
  RegqueryValueEx(reg.CurrentKey,'SubnetMask',nil,nil,@ZY,@Psize);
  Edit2.Text:=copy(ZY,0,strlen(ZY));
  RegqueryValueEx(reg.CurrentKey,'IPAddress',nil,nil,@ZY,@Psize);
  Edit1.Text:=copy(ZY,0,strlen(ZY));
  Reg.CloseKey;
  reg.Free;
  if pos(',',DNS)<=0 then begin Edit4.Text:=DNS;  end;
  if pos(',',DNS)>0 then
    begin
      Edit4.Text:=Copy(DNS,0,Pos(',',DNS)-1);
      Edit5.Text:=Copy(DNS,Pos(',',DNS)+1,Length(DNS));
    end;
end;

 读取IP

procedure TForm1.setIPAddr;
var
  reg:TRegistry;
  name:array [0..255] of char;
  DNS,ID,CardNum:string;
begin
  reg:=TRegistry.Create;
  StrLcopy(name,pchar(Edit6.Text),length(Edit6.Text));
  reg.RootKey:=HKEY_LOCAL_MACHINE;
  ID:=RGcardList.Items.Strings[RGCardList.itemindex];
  cardNum:=copy(ID,pos(';',ID)+1,length(ID));
  reg.CloseKey;
  if length(CardNum) < 2 then
    CardNum:='00'+CardNum;
  if LengTh(CardNum) < 3 then
    CardNum:='0'+CardNum;
  reg.OpenKey('SYSTEM\ControlSet'+CardNum+'\Services',false);
  reg.OpenKey('Tcpip\Parameters\Interfaces',false);
  ID:=CardIdLt.Strings[CardIDLt.IndexOf(ID)+1];
  reg.OpenKey(id,false);
  RegSetValueEx(reg.CurrentKey,'IPAddress',0,REG_MULTI_SZ,@name,13);

  StrLcopy(name,pchar(Edit7.Text),length(Edit7.Text));
  reg.RootKey:=HKEY_LOCAL_MACHINE;
  ID:=RGcardList.Items.Strings[RGCardList.itemindex];
  cardNum:=copy(ID,pos(';',ID)+1,length(ID));
  reg.CloseKey;
  if length(CardNum) < 2 then
    CardNum:='00'+CardNum;
  if LengTh(CardNum) < 3 then
    CardNum:='0'+CardNum;
  reg.OpenKey('SYSTEM\ControlSet'+CardNum+'\Services',false);
  reg.OpenKey('Tcpip\Parameters\Interfaces',false);
  ID:=CardIdLt.Strings[CardIDLt.IndexOf(ID)+1];
  reg.OpenKey(id,false);
  RegSetValueEx(reg.CurrentKey,'SubnetMask',0,REG_MULTI_SZ,@name,13);

  StrLcopy(name,pchar(Edit8.Text),length(Edit8.Text));
  reg.RootKey:=HKEY_LOCAL_MACHINE;
  ID:=RGcardList.Items.Strings[RGCardList.itemindex];
  cardNum:=copy(ID,pos(';',ID)+1,length(ID));
  reg.CloseKey;
  if length(CardNum) < 2 then
    CardNum:='00'+CardNum;
  if LengTh(CardNum) < 3 then
    CardNum:='0'+CardNum;
  reg.OpenKey('SYSTEM\ControlSet'+CardNum+'\Services',false);
  reg.OpenKey('Tcpip\Parameters\Interfaces',false);
  ID:=CardIdLt.Strings[CardIDLt.IndexOf(ID)+1];
  reg.OpenKey(id,false);
  RegSetValueEx(reg.CurrentKey,'DefaultGateway',0,REG_MULTI_SZ,@name,13);

  IF (Trim(Edit9.Text)='') And (Trim(Edit10.Text)='') Then Exit;
  IF (TRim(Edit9.Text)<>'') And (Trim(Edit10.Text)<>'') then
    begin
      DNS:=Trim(Edit9.Text)+','+TRim(Edit10.Text);
     end;
   IF (Trim(Edit9.Text)<>'') And (Trim(Edit10.Text)='') then
     begin
        DNS:=Trim(Edit9.Text);
      end;
   IF (Trim(Edit9.Text)='') And (Trim(Edit10.Text)<>'') then
     begin
        DNS:=Trim(Edit10.Text);
    end;
  StrLcopy(name,pchar(DNS),length(DNS));
  reg.RootKey:=HKEY_LOCAL_MACHINE;
  ID:=RGcardList.Items.Strings[RGCardList.itemindex];
  cardNum:=copy(ID,pos(';',ID)+1,length(ID));
  reg.CloseKey;
  if length(CardNum) < 2 then
    CardNum:='00'+CardNum;
  if LengTh(CardNum) < 3 then
    CardNum:='0'+CardNum;
  reg.OpenKey('SYSTEM\ControlSet'+CardNum+'\Services',false);
  reg.OpenKey('Tcpip\Parameters\Interfaces',false);
  ID:=CardIdLt.Strings[CardIDLt.IndexOf(ID)+1];
  reg.OpenKey(id,false);
 // RegSetValueEx(reg.CurrentKey,'NameServer',0,REG_MULTI_SZ,@name,13);
  reg.WriteString('NameServer',DNS);
  Reg.CloseKey;
  reg.Free;
end;

 设置IP

 

使用中还有一些问题,待完善


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi常用函数应用发布时间:2022-07-18
下一篇:
Delphi 10 Seattle 小票打印控件TQ_Printer发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap