当网络未连接时用windows API能否正常获取本机IP和MAC地址?若取不到,得到的结果是什么?急,在线等。

解决方案 »

  1.   

    你可以试试读注册表
    How to set local machine IP addresses from your program ? 
    (continued) 
    Follow this steps 
    1. Open registry on the HKEY_LOCAL_MACHINE 
    2. Find the subKey = SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\netcard# netcard# usually is "1" but you can control any subkey and find specific netwrok Adapters Refer to "MSDN Registry Entries for Network Adapter Cards" 
    3. Get data for the value "ServiceName" 
    4. Find the subKey = SYSTEM\CurrentControlSet\Services\"ServiceName"\Parameters\TcpIp" 
    5. Set data for the value "IpAddress" to change IP address 
    6. Set data for the value "SubnetMask" to change subnet mask 
    7. Set data for the value "DefaultGateway" to change default gateway 
    8. Reboot your PC. 
    忘了文章的作者是谁了,抱歉
    文章中说得有些问题,你要判断一下是动态IP还是静态分配的,动态IP要获取dhcpIPAddress和dhcpSubnetMask的值
      

  2.   

    本机IP不行。MAC地  可以。