문제

Specifically, I am creating a PDF using Essential Objects HtmlToPdf.

When the user clicks the "Create" button, I need to get the non-NAT ip address of the server (192.168.x.x) so that I can force it to create the PDF from that address, instead of the host name.

The overall problem is: on the web server, the host name for the site doesn't actually get you to the site because the DNS is specifying the external IP address which somehow is causing the connection to get blocked. So, for example-- www.testsite.com is translating to the public IP address, so the PDF creator on the server doesn't have access to that.

I created a host file entry forcing www.testsite.com to go to the internal ip. But that's a nightmare for multiple installations.

I tried

string hostName = HttpContext.Current.Request.Url.Host;
  IPHostEntry ipAddressList = Dns.GetHostEntry(hostName);
  string ipAddress = "";
  foreach (IPAddress ip in ipAddressList.AddressList)
  {
    if (ip.AddressFamily == AddressFamily.InterNetwork)
    {
      ipAddress = ip.ToString();
      break;
    }
  }

But that returns the DNSed IP (external) and then the firewall NATs that to the IP I want.

도움이 되었습니까?

해결책

var ips = NetworkInterface.GetAllNetworkInterfaces()
            .Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback)
            .Where(x => x.OperationalStatus == OperationalStatus.Up)
            .SelectMany(x => x.GetIPProperties().UnicastAddresses)
            .Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork)
            .Select(x => x.Address)
            .ToList();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top