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
الحاسوب
adxsadxcasxsd
adxcsdxsddxsd
Polygon Util
852
Test
K
Main4-4
Swap 1
MVC Learning