I am accessing a token generator that generates a token based on my IP (and my username & password). Since my code is running on App Service on Azure, it might use any of the out bound IPs that has been mentioned in the app service.
How can I understand which IP am I using at a time? I'm thinking of storing the token in a dictionary for each IP and then using it.
Is there any better way?
What I've found:
One is like below, but first, I don't like opening a socket separably every time. Secondly, is the IP the same on every call?
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
{
socket.Connect("8.8.8.8", 65530);
IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
localIP = endPoint.Address.ToString();
}
Is local IP the outbound or the inbound IP? I've also found this:
public static string GetLocalIPAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
throw new Exception("No network adapters with an IPv4 address in the system!");
}