Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Get Country IP
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Net; namespace Rextester { public class Program { public static void Main(string[] args) { Console.WriteLine(GetCountry()); } static protected string GetCountry() { //string clientIp = (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) ?? (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim(); string clientIp = "xxx.xxx.xx.xxx"; // RSA //string clientIp = "104.143.5.133"; US string xmlResult = new WebClient().DownloadString("https://freegeoip.net/xml/"+ clientIp); xmlResult = xmlResult.Substring(xmlResult.IndexOf("<CountryCode>")+13); int indexOfClosingTag = xmlResult.IndexOf("</CountryCode>"); xmlResult = xmlResult.Substring(0,indexOfClosingTag); return xmlResult; } } }
run
|
edit
|
history
|
help
0
iran
card 2
Validate or get the check digit of a Windows activation installation ID / confirmation ID
Numbers in Interval Dividable by Given Number
d
delete_xml_empty_tags
Fórum ➡ What values have the greatest frequency? ♦
Linq - When using FirstOrDefault, make sure to check for null result
RegEx
Cs