Alright, this question sounds a bit stupid, I know. I've looked at some of the other questions about it and I'm getting inconsistent results, even though I am finding the right answers. I'll try to lay it out as plainly as I can.
I have a problem where a large number of visitors to my site are using a ...I use the term popular very loosely, internet service (AOL) to access it. This is beyond my control. It is a large part of the userbase and I cannot stop them from using its built in browser (which derives from IE).
Now, this isn't the inherit problem. The problem is that any sites accessed through the browser go through one of their proxies. This does not cause any conflicts, but we need to know who is unique and who isn't for some specific reasons.
I have an installation of a popular message board system called "Invision Power Board". It tracks people's IP Address's and it has a feature to resolve an IP. So, I can click on an IP, and it will 'resolve' to a host like ..
IP XX.XXX.XX.XXX resolves to cache-dtc-ae16.proxy.aol.com.
Now I understand kind of what is going on here. cache-dtc-ae16.proxy.aol.com is a proxy, so I can't do much about that. I've come to terms with that. The code that does this is in IPB, and I don't speak PHP, so I'm SOL in that department.
I know how to get a User's IP Address.
HttpContext.Request.UserHostAddress
What I want to know is this ... from an IP, how can I 'resolve' to that proxy, in C#? I basically want to setup a specific part of code that denies anything from a proxy that has .aol. in it.
Does what I am trying to make any sense, is it even feasible or possible? I may be completely missing the terminology. I believe I understand this much.
UserHostAddress is the **client's** IP Address
Here is what I have tried, basically.
System.Net.Dns.GetHostEntry(System.Net.IPAddress.Parse(HttpContext.Request.UserHostAddress)).Aliases
are you trying to get the domain name from the ip?
it looks like your answer is in this question here
IPHostEntry IpToDomainName = Dns.GetHostEntry("209.85.129.103");
string HostName = IpToDomainName.HostName; //it returns "fk-in-f103.1e100.net"
This is a limitation of TCP protocol. The address is part of the TCP packet and as far as I know, routers and switches and NATs and proxies change the address and put their own.
As far as I know, there is no way around it. Proxy's address is as good as you gonna get.
I believe even TCP packet's MAC (physical) address is going to be proxy's but that is something to look at although not sure if you can get that in ASP.NET runtime since a request can come in multiple TCP packets.
try this
NullifyNetwork - A comprehensive Microsoft DNS Server management implementation in C#
Related
There's a similar question ( Can I temporarily override DNS resolution within a .NET application? ) but I just can't figure it out with the meager response there.
Background info
I have a server set up in my home network, an old computer. Our router has the right ports forwarded, the server runs server software for things like http, svn, games, etc. I've got a domain name registered that always points to our external IP address. For all intents and purposes, I've got a typical webserver set up. My friends can game on my server by connecting via the domain name, I can push and pull svn projects, etc.
The only problem is that I also need to use my server when I'm connected to my home network (the same network as the server). Using the domain name results in Windows resolving it to our own IP address, and my router is too retarded to realize it just needs to forward it back into our network to the server as per the usual. I've done some looking around, configuring, telnetting and DNS overriding, but I have it on good authority that our ISP apparently crippled the DNS override feature of their routers to prevent this exact scenario. Apparently they don't like internal loopbacks.
I now basically have to keep 2 configs for each of my server's services: one config that specifies the domain name for when I'm abroad, and a second that specifies the server's internal IP for when I'm at home. It's frustrating because it just isn't always possible.
I want to instantiate a global DNS resolution request/response listener that will do the following: if the requested domain name matches a given string, override the IP in the response with one of my choice.
I've looked things up like easyhook, dllimport, msdn pages, etc, but I still can't figure out where to actually start, which classes I need to get access to, and so on. I basically have no pre-existing code for this particular problem.
I have Visual Studio, years of relatively simple programming experience and a good understanding of unfamiliar code and everything else, just no idea how to start or what to look for.
Many thanks for anything that can get me going.
Couple of pointers, DNS is as you mentioned some server somewhere that knows how to resolve a Domain name to an IP ADDRESS. There are two types of responses 1) Definitive for the domain and 2) Not Definitive for the Domain. Obviously any Definitive response will win.
DNS does not run at TCP/IP layer it runs one layer below using UDP (port 53). As a result DNS is tied into the TCP/IP stack whereby the stack first looks locally to a local host table and sees is the name is there, if it cannot find it the stack will send out the DNS request prior to the session start or SYN packet flying. In order for this to happen, the DNS servers must resolve the address.
I do not fully understand your issue because most Windows servers only have 1 IP Address and one associated Domain name. Unless of course they are using DHCP which just means the server uses multiple address on boot up and DNS server receive updates to what those new address are.
Public vs. Private IP addresses are the responsibility of a router. The router is configured to do NAT (Network Address Translation). This allows a private server to have unroutable addresses like 10.10.1.100 etc. But the router will answer ARPs for the public address making the public network think the router is the public address. So one of your solutions could be to convert your server to a private address and use a "real" router that can perform NAT. Port forwarding is not really routing rather it's a way to "trick" packets destined for one port number to be forwarded to another port dedicated for that application.
My suggestion is to either follow the suggestions above or add the Domain names you want to the local Host table on the server. This will get you what you want. A better solution is to configure your own server to be a DNS server definitive for your domain, that way you get to control everything.
I ended up solving this with (as a few have suggested) the hosts file after all.
I first used ManagedWifi to set a network connection monitor. It detects changes to my connection status and reports the network name.
Then I wrote a console app that stays open (using Hidden Start allows me to hide the window) and safely modifies the hosts file, then flushes the DNS cache. This seems to work in pretty much realtime. :)
I want to get the IP address I am being NATed behind (e.g. the one presented to the outside world, rather than my local IP).
Something like the result you get from www.ipchicken.com.
How can I get this? The local IP info is easy to find, but I have no idea how to go about getting the IP assigned from the ISP.
The reason I need it is that my network infrastructure is such that I have two gateways out of the network. If one fails, it trips over transparently to the other. All well and good, but there is no alerting mechanism to tell me that I have failed over.
I believe it's quite hard to get this information. I guess another approach I could take is by putting a webservice on an externally hosted webserver - the idea being that it returns the IP of the querying host. (However, I have no idea how to do this either!) I suspect this might be the easiest way to go.
Your computer does not have access to this information locally; you need to get it from one of the many network services which do this.
There are lot's of ip services
This one, for example. Just make a GET request and parce a simple html : http://checkip.dyndns.org/
Some more details about this service (Policies and rules):
http://dyn.com/support/developers/checkip-tool/
upd
If you need to check your IP frequently you'd better to add your own web-service. .dyndns.org allows to check the ip once for 10 minutes.
You can run some .net code on web-service:
((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
But I think a script language (python?) will be more suitable.
Im sorry if this been asked before, but couldnt find anything about this particular matter.
I try to find out with which of my own ip's my computer use to connect to a remote ip.
I use some kind of socket setup both ways etc, and im sending my ip (and other stuff with xml) to another server so it knows how to contact me.
But how do i figure out which ip i should send to it?
I have the servers ip or host name, but trying with
Dns.GetHostEntry("host").AddressList
But that only gives me the ip of the remote host and not how my computer reach it.
Is my question solveable at all or is this just wishful thinking?
Can you have the remote host capture that data? That end would surely have it.
If you're using UDP then this is exactly what the STUN protocol was designed for. STUN is used in VOIP applications (among other P2P systems) to be able to tell what a specific connection looks like on the internet.
One very reliable .NET implementation that implements STUN is included in the Lumisoft.NET library (source code available here). I've used it myself for to satisfy this specific task for applications ranging from VOIP to P2P VPN alternatives. It is very easy to use and is standards compliant.
NOTE: I am NOT in any way affiliated with Lumisoft, I've merely used their library in several different applications
Ok, quick update that wont help anyone except myself.
But.
Found out that i can send hostname instead of actual ip, will work for now and most cases, and let the DNS do what its suppose to do :)
If you are programming an application which is heavily using the network (e.g. pings, dns resolves, etc), is it better to use IP addresses in the code (e.g. if making a folder path on a server - //192.183.181.182/test/test1 for example), or hostnames?
I am assuming IP addresses as they tend to be static in the enterprise, and hostnames can have aliases etc to a single IP address. Is this a valid reason to prefer IP addresses?
Thanks
The problem with using hardcoded IP addresses is that if you need to change it, you need to change the code, while if you use hostnames, if you need to change it, you can change where the hostname points, without touching the code :)
Fully agreeing with jcarlosn above, and throwing in my $0.02 as a network infrastructure guy...
As a network engineer, I could go on for quite some time about the number of instances where I've seen people mistakenly hard-code an IP into an application, and the suffering that happens for years because the company has to contort the growth of IT infrastructure around that original assumption of a hardcoded ip and a subnet in some particular facility. This has an impact on operational and capital expenses of the company.
Also consider what happens when that app is deployed on hundreds of PCs, and has now become business critical to your company and business partners.
Please use DNS names, or if you feel you must use an ip for some bizarre reason... use a local application config file as suggested in another post. Please understand though that a config file doesn't change the corporate downtime for a business-critical app to get migrated to a new IP address. If your desktop people are good, they can probably rewrite an application config file as quickly as you could migrate a DNS name... if you work for a company with no real scripting skills in the desktop deployment dept, please reconsider using DNS with no longer than a 30 minute TTL on that A record.
There are valid reasons for both. Multi-homed servers can cause issues when using names (as you mention), but IP addresses aren't necessarily stable either- especially in a DHCP environment that's not using reservations (more common than you might think).
If it were me, I'd put the path/hostname/IP in config- then you can change to whatever's needed without rebuilding the code. If you're doing name lookups yourself internally, just make sure your code is prepared for either an IP or a hostname.
IPv4 addresses (32bit addresses) are supposed to become obsolete in 2012,
(I think they made a movie about that, with earthquakes and tsunamis.)
There are already no new IPv4 addresses available for sale.
The new standard, IPv6, uses.much longer addresses.
Let the user decide, if he/she has a hostname, store that.
However, hostname may have more than 1 IP address.
If user provides an IP address (v4 or v6), store that.
If you get q MAC address, store that.
Explain the users pros and cons (e.g. names ate more static).
1 - How does it work? This question has come up because I am working with a guy for whom the call to System.Net.Dns.GetHostAddresses does not work. I gave him a sample app that just calls the aforementioned method and displays the IP addresses that are returned. Here is his explanation after using it:
When I try to resolve www.google.com [in the app]
it does not
work on the local workstations,
because our internal DNS do not
resolve external DNS names. [But] If I put
www.google.com in the browser, the
proxy server knows to go to the
external DNS servers for name
resolution and it resolves the name to
the IP address. Even if we put the
proxy server name in the application
it does not work when testing the
resolution.
I have done some packet sniffing on my work computer (which has a proxy server) and my personal computer (which does NOT have a proxy server) and there seem to be no packets sent or received durring the GetHostAddresses call. So, what exactly is that call doing?
2:
What port number is used?
Also asked by the person I am working with. I have no idea about this one. If there are no packets sent then it seems the answer would be there is no port being used, but I am not very savvy when it comes to ports and things like this. If anyone knows how to answer this or even a process for me to find the answer, please let me know.
DNS is a huge subject. Concerning Q1, it depends on how your machine is configured (node type). Googling on this should help you on the general principles.
Here is an answer about the ports: Network Ports Used by DNS
The reason in browser works and in command prompt does not is that browser has been setup to use a proxy and command prompt is not.
In order to see what code is used, use reflector. I have been told off to post any Microsoft code but I looked at the code and it was mainly unsafe and Win32 API calls.
The reason you're not seeing any network traffic when you use the packet sniffer could be that google.com is already in your local client DNS cache. If your browser has resolved it, it'll be in the cache. Try ipconfig /flushdns from the command line, and then use nslookup again to resolve google.com. I think you'll see some network traffic then.