Get the real IP IP countries provinces regions of thieves program
- 2020-05-12 02:32:03
- OfStack
This method is not very efficient, if used in WEB, if used less can be used this way, if often, or recommended to use the IP library
#region## Get real IP And location details
///<summary>
/// Get real IP And location details ( Porschev )
///</summary>
///<returns></returns>
public string GetIpDetails()
{
string url = "http://www.ip138.com/ips8.asp"; // Set up access IP Address and country source url
string regStr = "(?<=<td\\s*align=\\\"center\\\">)[^<]*?(?=<br/><br/></td>)";
string ipRegStr = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"; //IP regular
string ip = string.Empty; //IP address
string country = string.Empty; // countries
string adr = string.Empty; // Provinces and cities
string html = GetHtml(url); // Get the source
Regex reg = new Regex(regStr, RegexOptions.None);
Match ma = reg.Match(html); html = ma.Value;
Regex ipReg = new Regex(ipRegStr, RegexOptions.None);
ma = ipReg.Match(html);
ip = ma.Value; // get IP
int index = html.LastIndexOf(" : ") + 1;
country = html.Substring(index); // By the national
adr = GetAdrByIp(ip);
return "IP : " + ip + " Countries: " + country + " Provinces and cities: " + adr;
}
#endregion
#region## through IP get IP Provinces and cities
///<summary>
/// through IP get IP Province ( Porschev )
///</summary>
///<param name="ip"></param>
///<returns></returns>
public string GetAdrByIp(string ip)
{
string url = "http://www.cz88.net/ip/?ip=" + ip;
string regStr = "(?<=<span\\s*id=\\\"cz_addr\\\">).*?(?=</span>)";
string html = GetHtml(url); // Get the source
Regex reg = new Regex(regStr, RegexOptions.None);
Match ma = reg.Match(html);
html = ma.Value;
string[] arr = html.Split('');
return arr[0];
}
#endregion
#region## To obtain HTML Source of information
///<summary>
/// To obtain HTML Source of information (Porschev)
///</summary>
///<param name="url"> Get the address </param>
///<returns>HTML The source code </returns>
public string GetHtml(string url)
{
Uri uri = new Uri(url);
WebRequest wr = WebRequest.Create(uri);
Stream s = wr.GetResponse().GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.Default);
return sr.ReadToEnd();
}
#endregion