如何得到和修改本机IP?谢谢

解决方案 »

  1.   

    var
    Reg: TRegistry;
    begin
    Reg := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\System\CurrentControlSet\Services\Class\NetTran
    s\0000', True) then Reg.WriteString('IPAddress','192.168.1.1');//修改IP
    if Reg.OpenKey('\System\CurrentControlSet\Services\Class\NetTran
    s\0000', True) then Edit1.Text:=Reg.ReadString('IPAddress','');//读取IPReg.CloseKey;
    Reg.Free;
    end;
    end;
      

  2.   

    来慢了
    chenylin(陈SIR)已经解决了 正解
    顶一下
    分点分吧
      

  3.   

    用 WinExec或ShellExecute 执行 DOS命令 netshhttp://www.pcdog.com/tech/html/200521/12200513787_1.htm
      

  4.   

    虽然来迟了,但是我还是要贴出来,哈哈
    ///////////////获取本地计算机的IP地址function GetComputerIP: string;
    var
      ch: array[1..32] of Char;
      i: Integer;
      WSData: TWSAData;
      MyHost: PHostEnt;
      S_IP: string;
    begin
      if WSAstartup(2, wsdata) <> 0 then
        EXIT;
      if getHostName(@ch[1], 32) <> 0 then
        EXIT;
      MyHost := GetHostByName(@ch[1]);
      if MyHost = nil then
        EXIT
      else
      begin
        for i := 1 to 4 do
        begin
          S_IP := S_IP + inttostr(Ord(MyHost.h_addr^[i - 1]));
          if i < 4 then
            S_IP := S_IP + '.';
        end;
      end;
      RESULT := S_IP;
    end;
    /////////////