Solved

HELP: DNS

Posted on 2000-05-09
3
163 Views
Last Modified: 2010-04-04
Hi all!

I'm using D5 with the Windshoes WinshoeMappedPort. It works like a dream :-)

Q: For each connection made through the WinshoeMappedPort a thread is running. In each of these threads I want to make a DNS lookup (converting a name to ip).

So basicly I need some code that I can put inside the code of each thread (I don't with to use synchronized code, due to performance reasons).

If several DNS servers is available, I guess it would be smart to have multiple thread querying each of them. Please comment this issue.

Please note the DNS address can be either on a LAN or modem connection.

Source code would be very appreciated, something like
DNSQuery(ComputerName : String) : TStrings;
begin
  ?
end;

I know FPiette has an example using ICS, so don't give me that solution! If I can avoid it, I would try to stick to WinShoes.

Best regards,

Peter
0
Comment
Question by:jpvj
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
God_Ares earned 100 total points
ID: 2791916
uses WinSock;

function GetHostName(name : string) : string;
var
wsdata : TWSAData;
  he : PHostEnt;
  ip : TInAddr;            
begin
  WSAStartup(MakeWord(1, 1), wsdata);
  ip.S_addr := inet_addr(PChar(name));
  he := gethostbyaddr(@ip.S_un_b, 4, AF_INET);        
  if he<>nil then
    Result := string(he.h_name)
  else
    Result := IntToStr(WSAGetLastError);
  WSACleanup();
end;

function GetIPAddress(name : string) : string;
var wsdata : TWSAData;
    he : PHostEnt;
    ss : pchar;
    ip : TInAddr;
begin
  WSAStartup(MakeWord(1, 1), wsdata);
  he := gethostbyname(pchar(name));
  if he<>nil then
  begin
    ip.S_addr := integer(pointer(he^. h_addr_list^)^);
    ss := inet_ntoa(ip);
    Result := string(ss);
  end;
  WSACleanup();
end;
0
 

Author Comment

by:jpvj
ID: 2793741
Thanks a lot!

Peter
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 2795697
yeah shure no probl.. thanx for tha points...

yet again closer to my t-shirt :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now