How can I tell whether a controller action was requested by DNS or IP? - asp.net-mvc-2

On my WebDev server, I'm trying to test whether a controller's action was requested through its raw IP, or by its DNS. I've tried looking at the controller's HttpRequest.Url.HostNameType, but it seems to resolve to a DNS even if I enter my local IP in the browser. Any ideas? Thanks in advance.

That information is passed in the Host header of an HTTP request, so you should be able to access it like this:
var requestedHost = Request.Headers["Host"];
If the request was for an IP address, that IP address string should be returned. Otherwise, it will be whatever hostname they used.

HttpContext.Current.Request.Url.Authority
Gets the Domain Name System (DNS) host name or IP address and the port number for a server.
Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri,"shownew.htm?date=today");
Console.WriteLine(myUri.Authority);
Output: www.contoso.com:8080

Related

RestRequest Param Host not autocreate

Using Delphi 10, I have a TRESTClient with TRESTRequest to access an API.
I can't reach the server using its DNS hostname. There is a DNS problem on my network, and using the hostname I reach the wrong server. So I must use the server's IP address instead. But the API expects the Host request header to be the DNS hostname.
So I try to put a header like Host: auth-x.de in the request, like this:
RESTClient1.AddParameter('Auto', 'blau', TRESTRequestParameterKind.pkHTTPHEADER);
RESTClient1.AddParameter('Host', 'auth-x.de', TRESTRequestParameterKind.pkHTTPHEADER);
But when I send the request to the IP address, the component overwrites my Host header with the IP address.
The header Auto: blau (just for test) is sent just fine.
How can I prevent my Host header from being automatically overwritten?

Google Stun server stun.l.google.com change IP?

I was using the Google Stun server by IP 74.125.143.127, but since 21/09/2021 it seems Google changed the IP of DNS stun.l.google.com.
I know I should use DNS rather fixed IP.
Any guys have some confirmation about the IP change?
tks
I know I should use DNS rather fixed IP
Yes. That's the answer. Full stop. Don't hardcode IP addresses to services in your app. The whole point of DNS... well, you know this right?
Some recent DNS lookups:
stun.l.google.com: 74.125.197.127
stun1.l.google.com: 173.194.193.127
stun2.l.google.com: 172.253.112.127
stun3.l.google.com: 173.194.77.127
stun4.l.google.com: 172.217.215.127
Testing the old IP you referenced that's not in the DNS entries above:
>stunclient 74.125.143.127
Binding test: fail
Testing the IP address that's currently being returned:
>stunclient 173.194.193.127
Binding test: success
Local address: 192.168.1.18:55004
Mapped address: 1.2.3.4:55004

Access ingress IP from a pod

I have got an authentication service. This service is behind an ingress (GKE in my case) for external API calls. When the signup function of the authentication service is called, it will send an email for email verification purpose. The link in this email has to point to the IP of ingress. In order to achieve that, my authentication service has to know the IP of the ingress. How can this be configured dynamically in k8s without storing the ingress IP[ address in a config file?
Many thanks in advance
Regards
Since by default GKE allocates ephemeral external IP address the simplest solution is to reserve static ip address. This can be done with new one or you can promote existing ephemeral IP to static one. With this solution the IP address is known in advance but the drawback of that the IP would have to be hardcoded into the application.
To avoid hardcoding this you could use nslookup to find ip address for this specific host. With this you should update your dns records with an address type record to point to you reserved static IP address. Please refer to your DNS service`s documentation on setting DNS A records to configure your domain name.
For more reading check how to configure static ip address.
The alternative way would be also to access the Kubernetes REST API directly and fetch the IP address from there. This depending on your architecture and application design will required appropriate authentication towards API.

Website with dedicated IP Address, still uses shared server IP

Using cPanel WHM I have created a website hosting with Dedicated IP Address,
I'm planning to use it with the IP Address instead of a domain (e.g. http://1.2.3.4/script.php)
It opens, script also works fine.
The only issue is the IP address it uses isn't dedicated, it still uses server's shared IP.
I checked by CURL equivalent file_get_contents('http://myip.is') , the IP is the shared IP of server not the IP is use in URL or dedicated to it.
After a lot of tries, I realized the issue is because of CURL, apparently it still uses the server's main IP Address.
I managed to fixed this by adding the following to my CURL function
// Changing 1.2.3.4 with websites real IP
$website_ip = '1.2.3.4';
curl_setopt($curl, CURLOPT_INTERFACE, $website_ip);

Fusionpbx login fails after IP address change

I have a similar problem. My first network had a IP address range 192.168.1.xx and my freepbx server had 192.168.1.2
However now I need to move to a new network which has IP address in the range 192.168.2.xx and my freepbx server had 192.168.2.2
Now if I try to login to my freepbx server connected to the new network, the login always fails. Can anyhow help how to ensure freepbx/freeswitch will work on the new ip address?
thanks, -Anish
The users are per domain in FusionPBX. If you don't login with "user#192.168.1.2" then it will default to domain 192.168.2.2 that you use to access the website.
Once you have logged in you can edit the domain to change it's name. Also check for the old IP address in the variables.