Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# IPHostEnrty Cache???

Posted on 2004-08-20
5
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

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