//文件名:setup.rul
//脚本功能:通过主机名获得TCP/IP地址
//编写日期:2003-07-15
//使用方法:调用函数fGetIpAddress(szHost,szIPAdress)
//writtenbyJaron,2002-07-15
//原出处:江都资讯网论坛http://www.jiangdu.net/bbs;;
//转载请注明出处和保留此版权信息
//欢迎使用SiteManager网站管理系统http://sitemanager.cnzone.net;;
#include"Sddialog.h"
#include"IpAddress.rul"
STRINGszIPAddress;
STRINGszHostName;
BOOLnResult;
program
SdShowDlgEdit1("","请输入您的主机名称","主机名:",szHostName);
nResult=fGetIpAddress(szHostName,szIPAddress);
ifnResultthen
MessageBox("IP地址是:"+szIPAddress,INFORMATION);
endif;
endprogram
#include"Sddialog.rul"
==========================
//文件名:IpAddress.rul
//脚本功能:通过主机名获得TCP/IP地址
//编写日期:2003-07-15
//使用方法:
//1.在setup.rul前面加入#include"IpAddress.rul"
//2.调用函数fGetIpAddress(szHost,szIPAdress)
//writtenbyJaron,2002-07-15
//原出处:江都资讯网论坛http://www.jiangdu.net/bbs;;
//转载请注明出处和保留此版权信息
//欢迎使用SiteManager网站管理系统http://sitemanager.cnzone.net;;
prototypeNUMBERWSOCK32.WSAStartup(NUMBER,POINTER);
prototypeNUMBERWSOCK32.gethostbyname(STRING);
prototypeNUMBERKERNEL32.RtlMoveMemory(POINTER,NUMBER,NUMBER);
prototypeNUMBERWSOCK32.WSACleanup();
prototypefGetIpAddress(STRING,BYREFSTRING);
typedefWSADATA
begin
INTwversion;
INTwHighVersion;
STRINGszDescription[255];
STRINGszSystemStatus[128];
INTiMaxSockets;
INTiMaxUdpDg;
INTlpszVendorInfo;
end;
typedefHOSTENT
begin
NUMBERhName;//AsLong
NUMBERhAliases;//AsLong
SHORThAddrType;//AsInteger
SHORThLength;//AsInteger
NUMBERhAddrList;//AsLong
end;
typedefIPADDRESS
begin
CHARb1;//First
CHARb2;//Second
CHARb3;//Third
CHARb4;//Fourth
end;
functionfGetIpAddress(szHost,szIPAdress)
WSADATAStructWSAData;
WSADATAPOINTERpStructWSAData;
HOSTENTStructHostEnt;
HOSTENTPOINTERpStructHostEnt;
NUMBERnResult;
NUMBERpHostAddress;
POINTERpHostIPAddress;
NUMBERHostIPAddress;
IPADDRESSIpAddress;
IPADDRESSPOINTERpIpAddress;
STRINGsb1,sb2,sb3,sb4;
NUMBERnStartUp;
BOOLbReturn;
begin
ifszHost=""then
returnFALSE;
endif;
ifUseDLL(WINSYSDIR^"WSOCK32.DLL")<0then
returnFALSE;
endif;
pStructWSAData=&StructWSAData;
pStructHostEnt=&StructHostEnt;
nStartUp=WSAStartup(0x101,pStructWSAData);
ifnStartUp!=0then
returnFALSE;
endif;
pHostAddress=gethostbyname(szHost);
ifpHostAddress!=0then
RtlMoveMemory(pStructHostEnt,pHostAddress,16);
pHostIPAddress=&HostIPAddress;
RtlMoveMemory(pHostIPAddress,StructHostEnt.hAddrList,4);
pIpAddress=&IpAddress;
RtlMoveMemory(pIpAddress,HostIPAddress,4);
NumToStr(sb1,pIpAddress->b1);
NumToStr(sb2,pIpAddress->b2);
NumToStr(sb3,pIpAddress->b3);
NumToStr(sb4,pIpAddress->b4);
szIPAdress=sb1+"."+sb2+"."+sb3+"."+sb4;
bReturn=TRUE;
else
bReturn=FALSE;
endif;
ifnStartUp=0then
WSACleanup();
endif;
UnUseDLL("WSOCK32.DLL");
returnbReturn;
end;