Method of obtaining IP address by. Net


Get native IP


2. Get the IP address of the web client


/// <summary>    
  ///Get IPv4 address    
  /// </summary>    
  /// <returns>
  public static string GetIP4Address(HttpRequest request = null)    
  Func<IPAddress, bool> f = e => e.AddressFamily.ToString() == "InterNetwork";      
  IPAddress ipa = Dns.GetHostAddresses((request
  ?? HttpContext.Current.Request).UserHostAddress).FirstOrDefault(f)        
  ?? Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault(f);      
  if (ipa != null)     
  return ipa.ToString();    
  return HttpContext.Current.Request.UserHostAddress;   


The above is the method of. Net getting IP address introduced by Xiaobian to you. I hope it can help you. If you have any questions, please leave a message to me, and Xiaobian will reply you in time. Thank you very much for your support of the developepaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!