在InstallShield中通过主机名获取IP地址的代码
作者:
在InstallShield中通过主机名获取IP地址的代码
// 文 件 名:setup.rul
// 脚本功能:通过主机名获得TCP/IP地址
// 编写日期:2003-07-15
// 使用方法:调用函数 fGetIpAddress(szHost, szIPAdress)
// written by Jaron ,2002-07-15
// 原出处:江都资讯网论坛 http://www.jiangdu.net/bbs;;
// 转载请注明出处和保留此版权信息
// 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net;;
#include "Sddialog.h"
#include "IpAddress.rul"
STRING szIPAddress;
STRING szHostName;
BOOL nResult;
program
SdShowDlgEdit1 ("", "请输入您的主机名称", "主机名:", szHostName);
nResult = fGetIpAddress(szHostName, szIPAddress);
if nResult then
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)
// written by Jaron ,2002-07-15
// 原出处:江都资讯网论坛 http://www.jiangdu.net/bbs;;
// 转载请注明出处和保留此版权信息
// 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net;;
prototype NUMBER WSOCK32.WSAStartup( NUMBER, POINTER);
prototype NUMBER WSOCK32.gethostbyname(STRING);
prototype NUMBER KERNEL32.RtlMoveMemory (POINTER, NUMBER, NUMBER);
prototype NUMBER WSOCK32.WSACleanup();
prototype fGetIpAddress(STRING, BYREF STRING);
typedef WSADATA
begin
INT wversion;
INT wHighVersion;
STRING szDescription[255];
STRING szSystemStatus[128];
INT iMaxSockets;
INT iMaxUdpDg;
INT lpszVendorInfo;
end;
typedef HOSTENT
begin
NUMBER hName; // As Long
NUMBER hAliases; // As Long
SHORT hAddrType; //As Integer
SHORT hLength; // As Integer
NUMBER hAddrList; // As Long
end;
typedef IPADDRESS
begin
CHAR b1; //First
CHAR b2; //Second
CHAR b3; //Third
CHAR b4; //Fourth
end;
function fGetIpAddress(szHost, szIPAdress)
WSADATA StructWSAData;
WSADATA POINTER pStructWSAData;
HOSTENT StructHostEnt;
HOSTENT POINTER pStructHostEnt;
NUMBER nResult;
NUMBER pHostAddress;
POINTER pHostIPAddress;
NUMBER HostIPAddress;
IPADDRESS IpAddress;
IPADDRESS POINTER pIpAddress;
STRING sb1, sb2, sb3, sb4;
NUMBER nStartUp;
BOOL bReturn;
begin
if szHost = "" then
return FALSE;
endif;
if UseDLL(WINSYSDIR^"WSOCK32.DLL") < 0 then
return FALSE;
endif;
pStructWSAData = &StructWSAData;
pStructHostEnt = &StructHostEnt;
nStartUp = WSAStartup(0x101, pStructWSAData);
if nStartUp != 0 then
return FALSE;
endif;
pHostAddress = gethostbyname(szHost);
if pHostAddress != 0 then
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;
if nStartUp = 0 then
WSACleanup();
endif;
UnUseDLL("WSOCK32.DLL");
return bReturn;
end;
// 脚本功能:通过主机名获得TCP/IP地址
// 编写日期:2003-07-15
// 使用方法:调用函数 fGetIpAddress(szHost, szIPAdress)
// written by Jaron ,2002-07-15
// 原出处:江都资讯网论坛 http://www.jiangdu.net/bbs;;
// 转载请注明出处和保留此版权信息
// 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net;;
#include "Sddialog.h"
#include "IpAddress.rul"
STRING szIPAddress;
STRING szHostName;
BOOL nResult;
program
SdShowDlgEdit1 ("", "请输入您的主机名称", "主机名:", szHostName);
nResult = fGetIpAddress(szHostName, szIPAddress);
if nResult then
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)
// written by Jaron ,2002-07-15
// 原出处:江都资讯网论坛 http://www.jiangdu.net/bbs;;
// 转载请注明出处和保留此版权信息
// 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net;;
prototype NUMBER WSOCK32.WSAStartup( NUMBER, POINTER);
prototype NUMBER WSOCK32.gethostbyname(STRING);
prototype NUMBER KERNEL32.RtlMoveMemory (POINTER, NUMBER, NUMBER);
prototype NUMBER WSOCK32.WSACleanup();
prototype fGetIpAddress(STRING, BYREF STRING);
typedef WSADATA
begin
INT wversion;
INT wHighVersion;
STRING szDescription[255];
STRING szSystemStatus[128];
INT iMaxSockets;
INT iMaxUdpDg;
INT lpszVendorInfo;
end;
typedef HOSTENT
begin
NUMBER hName; // As Long
NUMBER hAliases; // As Long
SHORT hAddrType; //As Integer
SHORT hLength; // As Integer
NUMBER hAddrList; // As Long
end;
typedef IPADDRESS
begin
CHAR b1; //First
CHAR b2; //Second
CHAR b3; //Third
CHAR b4; //Fourth
end;
function fGetIpAddress(szHost, szIPAdress)
WSADATA StructWSAData;
WSADATA POINTER pStructWSAData;
HOSTENT StructHostEnt;
HOSTENT POINTER pStructHostEnt;
NUMBER nResult;
NUMBER pHostAddress;
POINTER pHostIPAddress;
NUMBER HostIPAddress;
IPADDRESS IpAddress;
IPADDRESS POINTER pIpAddress;
STRING sb1, sb2, sb3, sb4;
NUMBER nStartUp;
BOOL bReturn;
begin
if szHost = "" then
return FALSE;
endif;
if UseDLL(WINSYSDIR^"WSOCK32.DLL") < 0 then
return FALSE;
endif;
pStructWSAData = &StructWSAData;
pStructHostEnt = &StructHostEnt;
nStartUp = WSAStartup(0x101, pStructWSAData);
if nStartUp != 0 then
return FALSE;
endif;
pHostAddress = gethostbyname(szHost);
if pHostAddress != 0 then
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;
if nStartUp = 0 then
WSACleanup();
endif;
UnUseDLL("WSOCK32.DLL");
return bReturn;
end;