How to get domain name only using javascript?

Use location.host and cut off subdomains and the TLD: var domain = (location.host.match(/([^.]+)\.\w{2,3}(?:\.\w{2})?$/) || [])[1] update: as @demix pointed out, this fails for 2 and 3-letter domains. It also won’t work for domains like aero, jobs and dozens others. The only way around is to know valid TLDs in advance, so here is a more … Read more

How can I get a real IP address from DNS query in Swift?

Your code retrieves the address as a “socket address” structure. getnameinfo() can be used to convert the address into a numerical IP string (code recycled from https://stackoverflow.com/a/25627545/1187415, now updated to Swift 2): let host = CFHostCreateWithName(nil,”www.google.com”).takeRetainedValue() CFHostStartInfoResolution(host, .Addresses, nil) var success: DarwinBoolean = false if let addresses = CFHostGetAddressing(host, &success)?.takeUnretainedValue() as NSArray?, let theAddress = … Read more

Getting the IP address of server in ASP.NET?

This should work: //this gets the ip address of the server pc public string GetIPAddress() { IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); // `Dns.Resolve()` method is deprecated. IPAddress ipAddress = ipHostInfo.AddressList[0]; return ipAddress.ToString(); } http://wec-library.blogspot.com/2008/03/gets-ip-address-of-server-pc-using-c.html OR //while this gets the ip address of the visitor making the call HttpContext.Current.Request.UserHostAddress; http://www.geekpedia.com/KB32_How-do-I-get-the-visitors-IP-address.html