如何编程设置本机IP地址?

灰太狼 2022-08-23 14:49 278阅读 0赞

导读:

知道IP在什么位置,就可以更改了,看看下面这个

在NT上, 先获得网络设备驱动程序的名称:
sNetCardRegKey := ‘/SOFTWARE/Microsoft/Windows NT/CurrentVersion/NetworkCards/1’; 1 或者其他能在这个地方枚举到的子键
regRootKey.RootKey := HKEY_LOCAL_MACHINE;
regRootKey.OpenKeyReadOnly(SNetCardRegKey);
sNetCardDriverName := regRootKey.ReadString(‘ServiceName’);

然后:
sServiceRegKey := ‘/SYSTEM/CurrentControlSet/Services/‘;
sTCPIPRegKey := sServiceRegKey + sNetCardDriverName + ‘/Parameters/Tcpip’;
在’IPAddress’中获得这个设备的所有IP地址
regRootKey.ReadBinaryData(‘IPAddress’, cIPAddressArray, 255);
在’SubNetMask’中获得IP地址对应的子网掩码
regRootKey.ReadBinaryData(‘SubNetMask’, cNetMaskArray, 255);

在Win95/98中:
获得设备名称的办法:
sNetCardRegKey := ‘/Enum/Network/MSTCP/0001/‘; 0001 或者其他能在这个地方枚举到的子键
sServiceRegKey := ‘/SYSTEM/CurrentControlSet/Services/Class/‘;

regRootKey.RootKey := HKEY_LOCAL_MACHINE;
regRootKey.OpenKeyReadOnly(SNetCardRegKey);
sNetCardDriverName := regRootKey.ReadString(‘Driver’);

然后:
sTCPIPRegKey := sServiceRegKey + sNetCardDriverName;
regRootKey.OpenKeyReadOnly(sTCPIPRegKey);

最后获得IP地址和子网掩码:
sIPAddress := regRootKey.ReadString(‘IPAddress’);
sNetMask := regRootKey.ReadString(‘IPMask’);
Win95不支持一个设备对应多个地址

本文转自
http://topic.csdn.net/t/20021124/14/1201306.html

发表评论

表情:
评论列表 (有 0 条评论,278人围观)

还没有评论,来说两句吧...

相关阅读