Installshield脚本获取本地IP
Code
///////////////////////////////////////////////////////////////////////////////
//
// Tcp/Ip function
//
// By: Les Smith
// edit:haozes@gmail.com
//
///////////////////////////////////////////////////////////////////////////////
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
typedef
WSAData
begin
INT wVersion;
INT wHighVersion;
string szDescription[WSADESCRIPTION_LEN+1];
string szSystemStatus[WSASYS_STATUS_LEN+1];
short iMaxSockets;
short iMaxUdpDg;
POINTER lpVendorInfo;
end;
////////////////////
typedef HostEnt
begin
POINTER ph_name; /* official name of host */
POINTER ph_aliases; /* alias list */
short h_addrtype; /* host address type */
short h_length; /* length of address */
POINTER ph_addr_list; /* list of addresses */
end;
//////////////////
typedef IPName
begin
STRING szIPAddr[100];
end;
/////////////
typedef IPAddrList
begin
POINTER pIPAddr;
end;
/////////////
typedef IPAddPtr
begin
LONG nIPAddr;
end;
/////////////
prototype POINTER wsock32.gethostbyname(BYREF STRING);
prototype POINTER wsock32.gethostname(BYREF STRING, NUMBER);
prototype POINTER wsock32.WSAStartup(INT, POINTER);
prototype POINTER wsock32.inet_ntoa( NUMBER);
prototype POINTER wsock32.WSACleanup();
prototype int wsock32.WSAGetLastError ();
prototype STRING GetLocalIP();
function STRING GetLocalIP()
WSAData structWSAData;
WSAData POINTER pWSAData;
//
IPName LocalIPName;
IPName POINTER pLocalIPName;
//
IPAddrList structIPAddrList;
IPAddrList POINTER pIPAddrList;
IPAddPtr structIPAddPtr;
IPAddPtr POINTER pIPAddPtr;
POINTER pIN_Addr_Struct;
HostEnt structHostEnt;
HostEnt POINTER pHostEnt;
SHORT nlen;
NUMBER nIPNetAddr;
NUMBER nVersion;
STRING szMsg;
STRING szDefault;
STRING szURL;
STRING szPath;
NUMBER nRC;
NUMBER nRC2;
STRING szHostName;
STRING szMYIPAddr;
POINTER pWinSockReturn;
begin
pWSAData = &structWSAData;
nRC = UseDLL ("wsock32.dll");
pWSAData -> wHighVersion = 1;
pWSAData -> wVersion = 1;
nVersion = 0x02000002; // can be 0x01000001 for Windows NT but Windows 95 requires the version 2 settings
pWinSockReturn = WSAStartup(nVersion, pWSAData);
pWinSockReturn = gethostname(szHostName,100);
pHostEnt = gethostbyname(szHostName);
nlen = pHostEnt -> h_length; // debug check (should be 4)
pIPAddPtr = pHostEnt -> ph_addr_list;
pIPAddPtr = *pIPAddPtr;
nIPNetAddr = *pIPAddPtr;
// nIPNetAddr = pIPAddPtr -> nIPAddr;
pLocalIPName = inet_ntoa( nIPNetAddr );
szMYIPAddr = pLocalIPName -> szIPAddr;
WSACleanup();
UnUseDLL("wsock32.dll");
return szMYIPAddr;
end;
///////////////////////////////////////////////////////////////////////////////
//
// Tcp/Ip function
//
// By: Les Smith
// edit:haozes@gmail.com
//
///////////////////////////////////////////////////////////////////////////////
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
typedef
WSAData
begin
INT wVersion;
INT wHighVersion;
string szDescription[WSADESCRIPTION_LEN+1];
string szSystemStatus[WSASYS_STATUS_LEN+1];
short iMaxSockets;
short iMaxUdpDg;
POINTER lpVendorInfo;
end;
////////////////////
typedef HostEnt
begin
POINTER ph_name; /* official name of host */
POINTER ph_aliases; /* alias list */
short h_addrtype; /* host address type */
short h_length; /* length of address */
POINTER ph_addr_list; /* list of addresses */
end;
//////////////////
typedef IPName
begin
STRING szIPAddr[100];
end;
/////////////
typedef IPAddrList
begin
POINTER pIPAddr;
end;
/////////////
typedef IPAddPtr
begin
LONG nIPAddr;
end;
/////////////
prototype POINTER wsock32.gethostbyname(BYREF STRING);
prototype POINTER wsock32.gethostname(BYREF STRING, NUMBER);
prototype POINTER wsock32.WSAStartup(INT, POINTER);
prototype POINTER wsock32.inet_ntoa( NUMBER);
prototype POINTER wsock32.WSACleanup();
prototype int wsock32.WSAGetLastError ();
prototype STRING GetLocalIP();
function STRING GetLocalIP()
WSAData structWSAData;
WSAData POINTER pWSAData;
//
IPName LocalIPName;
IPName POINTER pLocalIPName;
//
IPAddrList structIPAddrList;
IPAddrList POINTER pIPAddrList;
IPAddPtr structIPAddPtr;
IPAddPtr POINTER pIPAddPtr;
POINTER pIN_Addr_Struct;
HostEnt structHostEnt;
HostEnt POINTER pHostEnt;
SHORT nlen;
NUMBER nIPNetAddr;
NUMBER nVersion;
STRING szMsg;
STRING szDefault;
STRING szURL;
STRING szPath;
NUMBER nRC;
NUMBER nRC2;
STRING szHostName;
STRING szMYIPAddr;
POINTER pWinSockReturn;
begin
pWSAData = &structWSAData;
nRC = UseDLL ("wsock32.dll");
pWSAData -> wHighVersion = 1;
pWSAData -> wVersion = 1;
nVersion = 0x02000002; // can be 0x01000001 for Windows NT but Windows 95 requires the version 2 settings
pWinSockReturn = WSAStartup(nVersion, pWSAData);
pWinSockReturn = gethostname(szHostName,100);
pHostEnt = gethostbyname(szHostName);
nlen = pHostEnt -> h_length; // debug check (should be 4)
pIPAddPtr = pHostEnt -> ph_addr_list;
pIPAddPtr = *pIPAddPtr;
nIPNetAddr = *pIPAddPtr;
// nIPNetAddr = pIPAddPtr -> nIPAddr;
pLocalIPName = inet_ntoa( nIPNetAddr );
szMYIPAddr = pLocalIPName -> szIPAddr;
WSACleanup();
UnUseDLL("wsock32.dll");
return szMYIPAddr;
end;