/ * Written by Jaron, 2002-07-15 * /
/ * Original: Jiangdu Information Network Forum
http://www.jiangdu.net/bbs ;; * /
/ * Reprinted please indicate the source and keep this copyright information * /
/ * Welcome to SiteManager Website Management System
http://sitemanager.cnzone.net ;; * /
// Document Name: setup.rul // Script Function: Get TCP / IP Address // By Host Name: 2003-07-15 // How to use: Call function FgetIPAddress (Szhost, Szipadress) // Written by Jaron , 2002-07-15 // Original: Jiangdu Information Network Forum http://www.jiangdu.net/bbs ;; // Reprinted Please indicate the source and retain this copyright information // Welcome to the 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 the MessageBox ("IP address is:" szipaddress, information; Endif; ENDIF ;
Endprogram # include "sddialog.rul"
============================================== From the host name, TCP / IP address // Write a date: 2003-07-15 // How to use: // 1. Add #include "ipaddress.rul" // 2. Call function fgetIpaddress (Szhost, Szipadress) // Written by Jaron, 2002- 07-15 // Original: Jiangdu Information Network Forum http://www.jiangdu.net/bbs ;; // Reprinted Please indicate the source and reserved this copyright information // Welcome to the 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 WsadataBegin Int Wversion; Int WHighversion; String Szdescription [255]; String SzsystemStatus [128]; Int ImaxSockets; Int iMaxUDPDG; int Lpszvendorinfo; end;
Typedef hostentbegin number hname; // as long number haddrtype; // as integer short hgength; // AS integer Number Haddrlist; // as lonnd;
Typedef ipaddressbegin char b1; // first char b2; // second char b3; // third char b4; // fours;
Function FgetIPAddress (Szhost, Szipadress) Wsadata Structwsadata; Wsadata Pointer PstructWsadata
Hostent structhostent; hostent pointer pstructure;
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"); returniturn;
END;