1
            string ipname;
            string strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            ipname = Convert.ToString(ipEntry.AddressList[1]);
            string cleanIP = ipname.Replace(".", string.Empty);
            string ipnew = cleanIP.Substring(6);
            string full_app_code = DateTime.Now.ToString("yyyymmddhhmmss", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ipnew + "H";

My result for "full_app_code" work fine when run in localhost, full_app_code ="201632221032461247H", why when i try to generate the full_app_code in production server it fail to generate, the output i get is ="20161823091804389d:2895:83f2:d3e2%17H"

KyLim
  • 468
  • 1
  • 6
  • 22
  • So what is wrong with what you get? Hint: ipv6 – zerkms Aug 23 '16 at 01:34
  • Here is another hint http://stackoverflow.com/questions/1059526/get-ipv4-addresses-from-dns-gethostentry – kurakura88 Aug 23 '16 at 01:39
  • @zerkms ,tried this (IPAddress[] ipv4Addresses = Array.FindAll( Dns.GetHostEntry(string.Empty).AddressList, a => a.AddressFamily == AddressFamily.InterNetwork);) but not working :( – KyLim Aug 23 '16 at 02:09
  • 1
    Not sure what "not working" means. – zerkms Aug 23 '16 at 02:19
  • 1
    Please clarify what you expect... Also please update title of your post "generate code" usually means creating some sort of C#/IL code... somewhat unrelated to what is shown in the post. – Alexei Levenkov Aug 23 '16 at 02:33

1 Answers1

1

add this (using System.Net.Sockets;)

var ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
var ipAddressOfMachine = ipHostEntry.AddressList.FirstOrDefault(addressListItem => addressListItem.AddressFamily == AddressFamily.InterNetwork);
KyLim
  • 468
  • 1
  • 6
  • 22