get Client public Ip address in web api - asp.net-mvc

i am using an service to get client country based on the ip address but it is made through web api rest service when i used UserHostAddress it shows internal ip only when i send this to service it is showing wrong country is there any solution to get country or ipaddresss

If you have local ip, and your router has the real one, your computer only communicates with router, and router communicates with Internet. There are two ways of getting routers IP:
Send http request to some site that shows your IP and get it from there.
Connect to router interface and get IP directly from router.

Related

Can I use my own device as redirect URI with OAuth2

I'm building an application in a device (Point of Sale) and for this I need to use OAuth servers to authenticate a webservice request, the guys on the side of the webservice are now asking me for a redirect URI, I do not have any experience on this so I started googling around 'redirect URI's, so now I wonder, given that this app works on a device (not on cloud), is there a way I can use my own device as the redirect URI and catch the webservice response there (such as the JSON)?
Extra info it might work (or not): In my office we all use DHCP but we have a configurable server.
Thank you.
It is possible to redirect to your own device if it is running its own web server.
This is because the redirect URI is passed back to the requesting client's browser which performs the redirect as shown in the diagram below from this tutorial. From there the browser can redirect to a local device's web server using the following approaches:
Use localhost or the 127.0.0.1 loopback IP for the redirect URI. This will work in the client's browser but not all services may allow registering a redirect URL to localhost or 127.0.0.1.
Use an external host which is mapped to the local system. On a Linux system, this can be configured by placing the hostname the /etc/hosts file and pointing it to the local system loopback IP address, e.g. 127.0.0.1. This can point to a real server on the Internet which is just redirected on the local system so this approach can be used with any service.
An example /etc/hosts file can contain a hostname like example.com which is then used in the redirect URI.
127.0.0.1 localhost example.com
Read more about localhost and the loopback IP address on Wikipedia:
https://en.wikipedia.org/wiki/Localhost
Diagram courtesy of TutorialsPoint.com.

Azure Application Gateway exit IPs

We're looking to use Application Gateway as a frontend\proxy for a website we host onsite. The website has a public IP but we'd like to restrict access to the site to only traffic coming from the Application Gateway. Is there a way to determine what IP the traffic would be coming from as it exits Azure? Is it like other Azure traffic where it could come from any IP subnet they have assigned to that specific region? I haven't seen this question asked and it's not directly referenced in any of MS documentation that I can find.
Thanks!
Not sure why you want to restrict access to the site to only traffic coming from the Application Gateway because if you configure it and add the website in the backend of Application Gateway. The traffic from a client will always reach the website through the Application gateway as the Application Gateway works as an application proxy by accepting traffic and based on rules that are defined with it, routes the traffic to the appropriate back-end instances.
You may want to know to restrict access on the application gateway subnet via NSG. Then the inbound or outbound traffic in the Application Gateway subnet will be filtered via NSG.
Network Security Groups (NSGs) are supported on the application
gateway subnet with the following restrictions:
Exceptions must be put in for incoming traffic on ports 65503-65534
for the Application Gateway v1 SKU and ports 65200 - 65535 for the v2
SKU. This port-range is required for Azure infrastructure
communication. They are protected (locked down) by Azure certificates.
Without proper certificates, external entities, including the
customers of those gateways, will not be able to initiate any changes
on those endpoints.
Outbound internet connectivity can't be blocked.
Traffic from the AzureLoadBalancer tag must be allowed.
Hope this will help, let me know if you have any other concerns.
Update
If you just want to whitelist the Azure service on the firewall, you can read the Azure Datacenter IP Ranges. You can figure out which datacenters your service are located in then narrow down the IP ranges.

Whitelisted azure outbound ip addresses not connecting to smtp server

Mostly just a question about the next steps to do to figure out why the azure test environment isn't connecting to my specified smtp server. Currently when finishing up my form, its supposed to email the information to a specific email and upon calling that I get a 500 internal server error. I've checked my solution and saw that on my personal ip, i connected and was denied access because my ip is not white listed. All of the outbound ip addresses in the azure environment are whitelisted, but i noticed when doing a ping in cmd to the test environment, I would just get the standard cloudapp.net ip. I've seen people solve this problem with a static ip. Are there other ways to do this without needing a static ip(mostly for trying to keep costs low)?
Thanks!
so the issue was that the outgoing ip addresses didn't match the ip address of the site. It was the external ip in custom domains that needed to be whitelisted in order to work.

Determine IP Address outgoing request comes from

If I have a link in an MVC application hosted on Azure:
Call web service
At the moment we are having difficulty connecting to the URL, which is a SOAP web service. We get an error 'site cannot be reached'.
Just to rule something out - what IP address would the service see this request coming from - my local (browser) or the server?
The request would come from your IP.

Provide access to a development web server running on laptop connected via iOS Personal Hotspot

I'm developing a web service that needs to connect to another web service and register a web service endpoint that notifications can be sent to.
e.g. Server A sends a registration request to Server B, containing the URL on which notifications will be sent (HTTP PUT).
If Server A (the development server) was on a public IP, all would be well, but at the moment its on my development laptop which is connected to the internet via a Wifi router which connects to Personal Hotspot on my iPhone. This is actually the most useful internet connection I have available most of the time. Neither the router nor Personal Hotspot (AFAIK) allow port forwarding or DMZ.
For development purposes I would like the notifications to come through to the service under development on my laptop. I can specify a static IP address when registering with the third-party web service, and a specific port number if needed.
My only thought was to use a VPN connection from the laptop to the internet, therefore masking the existence of the inbound route.
The VPN would therefore need to allow inbound packets through to the server. I've looked at the VPN service by VPNUK.info who I currently use, and they have both a dynamic IP and static IP version of their product, and the static version seems to suggest that inbound is possible.
Can anyone suggest how or if this would work? Any specific setup instructions? I presume once the VPN is established, and requests to the VPN Static IP address will be handled by the server on the development laptop (which is the device starting the VPN connection).
The development laptop is a Macbook running OS X Yosemite.
The web server is built using Node.js and Express.
I ended up signing up with VPN UK for a dedicated static IP VPN service. This gives a single publicly accessible IP address to the VPN connection.
Once the Macbook establishes the VPN, any requests to that IP address are routed to the Macbook as requested, so it doesn't matter where its located or the type/complexity of the internet connection.

Resources