views:

66

answers:

1

Hello. I am adding a feature to my current project that will allow network admins to install the software to the network. I need to code a DNS server in Python that will allow me to redirect to a certain page if the request address is in my list. I was able to write the server, just not sure how to redirect.

Thank you. I am using Python 2.6 on Windows XP.

+2  A: 

There's little, simple example here that can easily be adapted to make all kinds of "mini fake dns servers". Note that absolutely no "redirect" is involved (that's not how DNS works): rather, the request is for a domain name, and the result of that request is an IP address. If what you want to do is drastically different from translating names to addresses, then maybe what you need is not actually a DNS server...?

Alex Martelli
I guess it isn't. What would I need then? I thought I needed a proxy because I wanted it to be easy for network andims to use my program for web address filtering. If I ue a proxy, it can't be a "network wide" utility because there is not anywhere in most router settings to set a proxy.
Zachary Brown
@Zachary, I don't know what you need because I still don't understand what kind of "web address filtering" you're trying to accomplish -- I just answered the actual question you _asked_. If you're writing a web server that needs to respond differently depending on the IP that's doing the request, for example, that's obviously a completely different question (depending on your chosen web framework -).
Alex Martelli
...and if what you want is for your server to proxy to different ones, without technically being an HTTP proxy, that's feasible too, but _yet another_ completely different question. Please ask a different question specifying what you're trying to accomplish more precisely, and close this one!-)
Alex Martelli
Not quite sure. I have already written a proxy that blocks access to sites with certain keywords or addresses. Now I need a solution of the same type for an entire network. Maybe I need the DNS server to forward all requests through the proxy? If this is what I need, let me know and I will post that question. Thank you.
Zachary Brown
@Zachary, sure, you can have a DNS server that just _doesn't translate_ certain specified addresses (that's the only way in which a DNS server can "block access"!-) -- "forwarding to proxy" makes little sense unless your so-called "proxy" handles **every** protocol in the universe (including both TCP-based and UDP-based ones, but that's just a start), which would be a **very** weird "proxy" indeed (proxies normally handle a small number of protocols, often just HTTP and HTTPS -- and DNS servers are of course not informed of what protocol is in play).
Alex Martelli
Ok, so I would need to post a question asking about how to just not translate certain addresses? Or would it be able to return a specific ip for each listed address?
Zachary Brown
@Zachary, it's just as easy to do either -- simply fail name resolution for each of a certain set of given domain names, or direct each given domain name to a corresponding, given IP address. Please be aware of the utter, unusable ambiguity of the very vague term "address": a DNS server gets a **domain name** as input, returns an **IP address** (or an error;-) as the result, and that's **all** you should be thinking of (mail-exchangers and other complex refinements are really out of the interesting domain of discourse in your context, I think;-).
Alex Martelli
So I need to look at it this way... The user requests a domain, the DNS server checks to see if it is one of the domains that should not be allowed.... if it is, it returns an IP address of another site ( this will have a page that explains it was blocked ) and if not it will return the IP address of the correct site, right?
Zachary Brown