当DELPHI程序检测到本机为自动获取IP地址时,将自动获取到的IP地址,子网掩码,网关及DNS以手工指派方式填写到对应参数.
需要考虑到:
一,多网卡 
二,不同OS(XP,2003)感觉挺简单的问题,找来找去找不到方法.几度疯掉.
请高手指点,附原码最好.

解决方案 »

  1.   

    这个肯定是系统的KPI能够搞定的。查阅一下MSDN
      

  2.   

    大概一看就是先判断DHCP服务是否自动启动.
    如果是的话,就将本机的IP,子网,网关等信息分配给各个参数...
    是吧?
      

  3.   

    需要修改系统注册表:给一段代码。供参考:
    //修改IP开始
        if regRootKey.OpenKey('\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + CardList.Strings[cbb1.ItemIndex], True)
        then begin
          if CheckBox1.Checked // 判断是否启用DHCP
          then begin
            regRootKey.WriteInteger('EnableDHCP',1);
            regRootKey.WriteString('NameServer','');
            WriteIp(regRootKey.CurrentKey, 'IPAddress', '0.0.0.0');
            WriteIp(regRootKey.CurrentKey, 'SubNetMask','0.0.0.0');
            WriteIp(regRootKey.CurrentKey, 'DefaultGateway','');
          end
          else begin
            regRootKey.WriteInteger('EnableDHCP',0);
            regRootKey.WriteString('NameServer', Trim(Combobox1.Text));
            WriteIp(regRootKey.CurrentKey,'IPAddress',Trim(Edit2.Text));
            WriteIp(regRootKey.CurrentKey, 'DefaultGateway', Trim(Edit4.Text));
            WriteIp(regRootKey.CurrentKey, 'SubNetMask', Trim(Edit3.Text));
            WriteIp(regRootKey.CurrentKey, 'DefaultGateway', Trim(Edit4.Text));
          end;
        end;
      

  4.   

    我一个龌龊办法:Delphi程序调用  cmd /c c:\windows\system32\ipconfig.exe /all >c:\cc.txt后,会在c:\ 下生成一个cc.txt 文件, 打开看看这个文件内容是什么就知道了。接下来读取这个文件内容,并根据关键字:
    IP Address、Subnet Mask 、Default Gateway .... 来获取你要的东西。 哈哈。 
      

  5.   

    这里的关键是DOS命令可以用一个输出转向符“>”,让命令结果输出到一个文件中。 巧妙利用这个功能有时能起到意想不到的作用,帮你解决大问题。 可惜很80后、90后的TX 可能不知道了。
      

  6.   

    调用几个API就行了 API头文件Iphlpapi Mprapidll := LoadLibrary('Mprapi.dll');
      if  Mprapidll <32 then
        Exit;
      MprConfigGetFriendlyName := GetProcAddress(Mprapidll,'MprConfigGetFriendlyName');
      MprConfigServerConnect := GetProcAddress(Mprapidll,'MprConfigServerConnect');
      lpwsServerName := '';
      dwRet := MprConfigServerConnect(PWideChar(lpwsServerName),@hMprConfig);  try
      while (pAdapter <> nil) do
      begin
        i := i+1;
        begin
    //      cbbNetName.Items.Add(pAdapter.Description);
          NetInformation[i-1].Description := pAdapter.Description;//网卡描述
          NetInformation[i-1].IpAddress := StrPas(pAdapter.IPAddressList.IpAddress);//IP地址
          NetInformation[i-1].IpMask :=  StrPas(pAdapter.IPAddressList.IpMask);//网关
          while (pAdapter.IPAddressList.Next <> nil) do
          begin
            pAdapter.IPAddressList := pAdapter.IPAddressList.next^;
          end;
          str := IntToStr(pAdapter.Address[1]);
        end;
        //获取本地连接名称
        //Wszfriendname := GetWideString(string(szFriendName));
        AdapterName := pAdapter.AdapterName;
        WAdapterName := AdapterName;
        PWAdapterName := PWideChar(WAdapterName);
        dwRet := MprConfigGetFriendlyName(hMprConfig,PWAdapterName,@FriendName[0],500);
        Wszfriendname := FriendName;
        szFriendName := Wszfriendname;
        NetInformation[i-1].Name :=  szFriendName;//本地连接名    pAdapter := pAdapter.Next;
      end;
      FreeMemory(pAdapterInfo) ;
      pAdapter := nil;
      except
        i := 0;
      end;
      

  7.   

    前面少贴了点代码 不好意思
    BufLen := SizeOf(TIP_ADAPTER_INFO);
      pAdapter := nil;
      pAdapterInfo := GetMemory(SizeOf(TIP_ADAPTER_INFO)) ;
      if GetAdaptersInfo(pAdapterInfo,@BufLen)= ERROR_BUFFER_OVERFLOW then
      begin
        FreeMemory(pAdapterInfo) ;
        pAdapterInfo := GetMemory(BufLen) ;
        GetAdaptersInfo(pAdapterInfo,@BufLen);
      end;  pAdapter :=  pAdapterInfo;