Code for obtaining an IP address through the host name in InstallShield

Source: Internet
Author: User

// File name: setup. rul
// Script Function: Obtain the TCP/IP address through the host name
// Written on:
// Usage: Call the fgetipaddress (szhost, szipadress) function)
// Written by jaron, 2002-07-15
// Original Source: jiangdu Information Network Forum http://www.jiangdu.net/bbs.pdf ;;
// Indicate the source and retain the copyright information.
// Welcome to SiteManager website management system http://sitemanager.cnzone.net ;;

# Include "sddialog. H"
# Include "IPaddress. rul"

String szipaddress;
String szhostname;

Bool nresult;

Program

Sdshowdlgedit1 ("", "Enter your host name", "Host Name:", szhostname );
Nresult = fgetipaddress (szhostname, szipaddress );
If nresult then
MessageBox ("IP Address:" + szipaddress, information );
Endif;

Endprogram
# Include "sddialog. rul"

======================================
// File name: IPaddress. rul
// Script Function: Obtain the TCP/IP address through the host name
// Written on:
// Usage:
// 1. Add # include "IPaddress. rul" before setup. rul"
// 2. Call the fgetipaddress (szhost, szipadress) function)
// Written by jaron, 2002-07-15
// Original Source: jiangdu Information Network Forum http://www.jiangdu.net/bbs.pdf ;;
// Indicate the source and retain the copyright information.
// Welcome to 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; // 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 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;

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.