Sample code - IP Address lookup

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Sample code - IP Address lookup

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

by Robert Barr >> Mon, 22 Jan 2001 5:10:58 GMT

The attached sample code is again in response to a client request for assistance - how do I translate an IP address to a DNS name?

In fact, the lookup is performed by the Windows nslookup command-line function. A shell() method redirects the output from this command to a file, then returns the file contents). The other methods handle nslookup input/output format. The lookup works both ways (provides the IP
address, given the domain name).

Platform: JADE 5.1.08, MS-Windows

(Note an NFS has been raised to request node.createExternalProcess() is enhanced to use stdin/stdout/stderr I/O devices as per Unix command convention).

------------------------------------------------------------------------- Aoraki Corporation Limited (Aoraki) believes that this software is accurate and reliable and has been prepared with care but can give no guarantee that the software will be free of defects or errors. No responsibility or liability, financial or otherwise, can be accepted for any consequences arising out of the use of this software including loss of profits, indirect, special or consequential losses or damages.
Attachments
1836_4.mth
(1.57 KiB) Downloaded 189 times
1836_3.mth
(915 Bytes) Downloaded 178 times
1836_2.mth
(1.11 KiB) Downloaded 181 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 3:57 pm, edited 1 time in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Sample code - IP Address lookup

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

by Wilfred Verkley >> Mon, 22 Jan 2001 20:44:33 GMT
In fact, the lookup is performed by the Windows nslookup command-line function. A shell() method redirects the output from this command to a file, then returns the file contents). The other methods handle nslookup input/output format. The lookup works both ways (provides the IP
address, given the domain name).

There are two simple winsock API functions in wsock32.dll that actually perform this, gethostbyaddr and gethostbyname. However, by themselves they cant be used by Jade since they return pointers, and Jade has virtually no memory or record manipulation functions.

This functionality is so common when doing any kind of TCP/IP programming, couldnt it be exposed to the TCPIPConnection class, or to Root/CardSchema?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Sample code - IP Address lookup

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

by Richard Mitchell >> Tue, 23 Jan 2001 1:14:34 GMT

If you are using CardSchema, then the CnKarmaCntrl class has a method emGetHostByAddress which you can use.

emGetHostByAddress( ipAddress: String; hostName: String output): Integer is "emGetHostByAddr" in "karma"

Cheers


--
Richard Mitchell
JADE Systems Group
Ext 3722

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Sample code - IP Address lookup : updated

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

by Richard Mitchell >> Tue, 23 Jan 2001 1:22:06 GMT

If you are using CardSchema, then the CnKarmaCntrl class has a method
emGetHostByAddress which you can use, with the signature.

emGetHostByAddress( ipAddress: String; hostName: String output): Integer is
emGetHostByAddr" in "karma".

Since schemas that use CardSchema normally instantiate the CnKarmaCntrl singleton at application initialisation time, you can use app.myCnKarmaCntrl to access this instance and thus use the method. Sample code from CardSchema, including error handling, can be seen in CnKarmaCntrl::getAddressInfo.

Cheers

Richard Mitchell
JADE Systems Group
Ext 3722


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 30 guests