Solved

C# IPHostEnrty Cache???

Posted on 2004-08-20
5
379 Views
Last Modified: 2009-12-16
Here is one of the coolest few lines of code to perform a NSLookUp. Simply enter an IP in textBox1, click a button and the domain name translates in textBox2 (providing your workstation is on a WAN.

Q. How could we build a 'cache' to capture redundant IP's/Domain's to add lookup performance???

Q. How could we add our own know IP's/Domain's to this 'cache' ??? (Because NOT every IP will resolve)

 Preferably the code would check our personal 'cache' first before looking on the Internet or elsewhere.....

public void ButtonLookupDomain_Click(object sender, EventArgs ea)
{
IPHostEntry IP = Dns.Resolve(textBox1.Text);
txtBox2.Text = IP.HostName;
}
0
Comment
Question by:kvnsdr
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 11857844
What is the motivation for implementation of your own?  Your PC does DNS caching already, and you can add known hosts to the hosts file found in system32/drivers/etc.

A home-grown DnsCache would be a wrapper around some data structure with associated accessor functions.  Exact details depend on how you plan to use the information.
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 11858945
Yes I know about the 'hosts' file. We call it the "poor mans DNS", and it does work quite well. The fact is I've searched very long and to my amazment a 'Dns.Cache' class doesn't seem to exist. So, if we are inovative coders, this should be a welcome challenge to those who would like to work on it with me. That's why I put 500 points on it. No, it's not "Re-Inventing the Wheel" either. I could say that about many coding practices. I just think it would be cool to create a Dns.Cache class with these points

1. Build a 'cache' to capture redundant IP's/Domain's to add lookup performance. (Takes a load of your local ISP)

2. The ability to add our own know IP's/Domain's to this 'cache'. (Because if you own an IP block, only the IP associated with your Domain will resolve.)

0
 
LVL 19

Accepted Solution

by:
drichards earned 500 total points
ID: 11859004
OK, then let's clarify exactly what your goal is because Windows HAS a DNS cache.  If you are connecting to the same DNS name multiple times, Windows only does 1 DNS query.  You can easily verify this with a netwotk analyzer.  Take a look at this url:

http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prjj_ipa_vitx.asp

You have some control over the operation of this cache and you can certainly read it.  Unfortunately, I don't know how to write to it (as far as I know you can't), but that's where the hosts file comes in.  Any address that won't resolve through DNS can be added to the hosts file.

So given that, what do you want your cache to do that the Windows cache does not already do?

Also, what do you mean by "(Because if you own an IP block, only the IP associated with your Domain will resolve.) "?  With correct DNS server configuration, all IP's should resolve.

0
 
LVL 1

Author Comment

by:kvnsdr
ID: 11865798
That was good reading... The more I study windows DNS, I realize my goal is to create my own 'hosts' file. I can write to it and IPHostEntry can read from it. Much like some mail server programs and security programs have thier own seperate 'black lists' or 'white lists'. Keeping my host entries seperate like other programs is smart for many reasons, especially is something goes wrong or I ever uninstall my program..........Below is a scribling of an idea to work with........

if(hostsFile.Contains(textBox1.Text))
{
   textBox2 = (hostsFile[textBox1.Text] as IPHostEntry).HostName;
}
else
{
IPHostEntry IP = Dns.Resolve(textBox1.Text);
txtBox2.Text = IP.HostName;
}

Q. How can I create my own 'hosts' file with the correct formatting (tab delimited, newline) and the correct code to make it work???
0
 
LVL 19

Expert Comment

by:drichards
ID: 11878454
If you want to make your own hosts file for use by your app, you can do that pretty much any way you want.  Standard format is:

<address> <name>

on each line.  You'd probably read this into some kind of live data structure and write it back out to the file when modified.  You don't want to have to read the file each time you need to look something up.  Implementation depends on how you plan to use it.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

18 Experts available now in Live!

Get 1:1 Help Now