Code to obtain an IP address by host name in InstallShield _ Other

Source: Internet
Author: User
FileName: Setup.rul
Scripting feature: Obtaining TCP/IP addresses via host name
Date of preparation: 2003-07-15
How to use: Call function fgetipaddress (Szhost, szipadress)
Written by Jaron, 2002-07-15
Original source: Jiangdu Information Network forum Http://www.jiangdu.net/bbs;
Reprint please indicate the source and retain this copyright information
Welcome to use Sitemanager website management system http://sitemanager.cnzone.net;;

#include "Sddialog.h"
#include "Ipaddress.rul"

STRING szipaddress;
STRING Szhostname;

BOOL Nresult;

Program

SdShowDlgEdit1 ("", "Please enter your host name", "Host Name:", Szhostname);
Nresult = Fgetipaddress (Szhostname, szipaddress);
If Nresult Then
MessageBox ("IP address is:" + szipaddress, information);
endif

Endprogram
#include "Sddialog.rul"


==========================
FileName: Ipaddress.rul
Scripting feature: Obtaining TCP/IP addresses via host name
Date of preparation: 2003-07-15
How to use:
1. Join #include "Ipaddress.rul" in front of Setup.rul
2. Call function fgetipaddress (Szhost, szipadress)
Written by Jaron, 2002-07-15
Original source: Jiangdu Information Network forum Http://www.jiangdu.net/bbs;
Reprint please indicate the source and retain this copyright information
Welcome to use Sitemanager website management system 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; The
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-&GT;B1);
Numtostr (SB2, PIPADDRESS-&GT;B2);
Numtostr (SB3, PIPADDRESS-&GT;B3);
Numtostr (SB4, PIPADDRESS-&GT;B4);

szipadress = Sb1 + "." + SB2 + "." + SB3 + "." + sb4;

Breturn = TRUE;

Else
Breturn = FALSE;

endif

If Nstartup = 0 Then
WSACleanup ();
endif

Unusedll ("WSOCK32.") DLL ");

return breturn;

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.