delphi版不重启改ipdns网关.docx

上传人:b****2 文档编号:1863920 上传时间:2022-10-24 格式:DOCX 页数:9 大小:15.46KB
下载 相关 举报
delphi版不重启改ipdns网关.docx_第1页
第1页 / 共9页
delphi版不重启改ipdns网关.docx_第2页
第2页 / 共9页
delphi版不重启改ipdns网关.docx_第3页
第3页 / 共9页
delphi版不重启改ipdns网关.docx_第4页
第4页 / 共9页
delphi版不重启改ipdns网关.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

delphi版不重启改ipdns网关.docx

《delphi版不重启改ipdns网关.docx》由会员分享,可在线阅读,更多相关《delphi版不重启改ipdns网关.docx(9页珍藏版)》请在冰豆网上搜索。

delphi版不重启改ipdns网关.docx

delphi版不重启改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]of

 

Char;

 

AddressLength:

UINT;

 

Address:

 

array[0..MAX_ADAPTER_ADDRESS_LENGTH-1]of

 

BYTE;

 

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\I

 

nterfaces\'+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.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1