pascaldelphi delphi版不重启改ipdns网关.docx
- 文档编号:28652
- 上传时间:2022-10-01
- 格式:DOCX
- 页数:5
- 大小:11.41KB
pascaldelphi delphi版不重启改ipdns网关.docx
《pascaldelphi delphi版不重启改ipdns网关.docx》由会员分享,可在线阅读,更多相关《pascaldelphi delphi版不重启改ipdns网关.docx(5页珍藏版)》请在冰豆网上搜索。
pascaldelphidelphi版不重启改ipdns网关
[Pascal(Delphi)]delphi版不重启改ip、dns、网关
programMASK;
uses
windows,SysUtils;const
MAX_ADAPTER_NAME_LENGTH=256;
MAX_ADAPTER_DESCRIPTION_LENGTH=128;
MAX_ADAPTER_ADDRESS_LENGTH=8;
IPHelper='iphlpapi.dll';type
USHORT=WORD;
ULONG=DWORD;
time_t=Longint;IP_ADDRESS_STRING=record
S:
array[0..15]ofChar;
end;IP_MASK_STRING=IP_ADDRESS_STRING;
PIP_MASK_STRING=^IP_MASK_STRING;PIP_ADDR_STRING=^IP_ADDR_STRING;
IP_ADDR_STRING=record
Next:
PIP_ADDR_STRING;
IpAddress:
IP_ADDRESS_STRING;
IpMask:
IP_MASK_STRING;
Context:
DWORD;
end;PIP_ADAPTER_INFO=^IP_ADAPTER_INFO;
IP_ADAPTER_INFO=record
Next:
PIP_ADAPTER_INFO;
ComboIndex:
DWORD;
AdapterName:
array[0..MAX_ADAPTER_NAME_LENGTH+3]ofChar;
Description:
array[0..MAX_ADAPTER_DESCRIPTION_LENGTH+3]ofChar;
AddressLength:
UINT;
Address:
array[0..MAX_ADAPTER_ADDRESS_LENGTH-1]ofBYTE;
Index:
DWORD;
Type_:
UINT;
DhcpEnabled:
UINT;
CurrentIpAddress:
PIP_ADDR_STRING;
IpAddressList:
IP_ADDR_STRING;
GatewayList:
IP_ADDR_STRING;
DhcpServer:
IP_ADDR_STRING;
HaveWins:
BOOL;
PrimaryWinsServer:
IP_ADDR_STRING;
SecondaryWinsServer:
IP_ADDR_STRING;
LeaseObtained:
time_t;
LeaseExpires:
time_t;
end;functionGetAdaptersInfo(pAdapterInfo:
PIP_ADAPTER_INFO;varpOutBufLen:
ULONG):
DWORD;stdcall;externalIPHelper;functionStringToWideString(constS:
string):
WideString;
var
InputLength,OutputLength:
Integer;
begin
InputLength:
=Length(S);
OutputLength:
=MultiByteToWideChar(CP_ACP,0,PChar(S),InputLength,nil,0);
SetLength(Result,OutputLength);
MultiByteToWideChar(CP_ACP,0,PChar(S),InputLength,PWideChar(Result),OutputLength);
end;functionNotifyIPChange(lpszAdapterName:
string):
bool;
typeTDhcpNotifyConfigChange=function(lpwszServerName:
PWideChar;//本地机器为NULL
lpwszAdapterName:
PWideChar;//适配器名称
bNewIpAddress:
BOOL;//TRUE表示更改IP
dwIpIndex:
DWORD;//指明第几个IP地址,如果只有该接口只有一个IP地址则为0
dwIpAddress:
DWORD;//IP地址
dwSubNetMask:
DWORD;//子网掩码
nDhcpAction:
Integer):
BOOL;stdcall;
var
hDhcpDll:
dword;
MyDhcpNotifyConfigChange:
TDhcpNotifyConfigChange;
begin
hDhcpDll:
=LoadLibrary('dhcpcsvc.dll');
ifhDhcpDll<>0then
begin
MyDhcpNotifyConfigChange:
=GetProcAddress(hDhcpDll,'DhcpNotifyConfigChange');
MyDhcpNotifyConfigChange(nil,pwidechar(StringToWideString(lpszAdapterName)),FALSE,0,0,0,0)
end;
CloseHandle(hDhcpDll);
end;functionRegIp(lpszAdapterName,pIPAddress,pNetMask,pNetGate,pDNSServer1,pDNSServer2:
string):
bool;
var
hkRoot:
HKEY;
mszDNSServer,mszIPAddress,mszNetMask,mszNetGate:
string;
strKeyName:
string;
begin
strKeyName:
='SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\'+lpszAdapterName;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,pchar(strKeyName),0,KEY_WRITE,hkRoot)<>ERROR_SUCCESS)
thenexit;
mszDNSServer:
=pDNSServer1+','+pDNSServer2;
mszIPAddress:
=pIPAddress+#0#0;
mszNetMask:
=pNetMask+#0#0;
mszNetGate:
=pNetGate+#0#0;
RegSetValueEx(hkRoot,'IPAddress',0,REG_MULTI_SZ,pchar(mszIPAddress),length(mszIPAddress));
RegSetValueEx(hkRoot,'SubnetMask',0,REG_MULTI_SZ,pchar(mszNetMask),length(mszNetMask));
RegSetValueEx(hkRoot,'DefaultGateway',0,REG_MULTI_SZ,pchar(mszNetGate),length(mszNetGate));
RegSetValueEx(hkRoot,'NameServer',0,REG_SZ,pchar(mszDNSServer),length(mszDNSServer));
RegCloseKey(hkRoot);
end;functionGetLanAdapterName:
string;
var
InterfaceInfo,TmpPointer:
PIP_ADAPTER_INFO;
IP:
PIP_ADDR_STRING;
Len:
ULONG;
begin
result:
='';
ifGetAdaptersInfo(nil,Len)=ERROR_BUFFER_OVERFLOWthen
begin
GetMem(InterfaceInfo,Len);
try
ifGetAdaptersInfo(InterfaceInfo,Len)=ERROR_SUCCESSthen
begin
TmpPointer:
=InterfaceInfo;
result:
=TmpPointer.AdapterName;
end;
finally
FreeMem(InterfaceInfo);
end;
end;
end;var
AdapterName:
string;
begin
AdapterName:
=GetLanAdapterName;
RegIp(AdapterName,'192.168.0.5','255.255.255.0',11.10.10.1',111.111.11.111','111.111.11.112');
NotifyIPChange(AdapterName);
end.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- pascaldelphi delphi版不重启改ipdns网关 delphi 版不重启改 ipdns 网关