Get real outside IP, IP country, province, Region (Thief Program) _ Practical Skills

Source: Internet
Author: User
Tags get ip ip country
This approach is not very efficient, if used in the web, if used less can be used in this way, if used, or recommend the use of IP library
Copy Code code as follows:

#region # #得到真实IP以及所在地详细信息
<summary>
Get real IP and location details (Porschev)
</summary>
<returns></returns>
public string Getipdetails ()
{
String url = "Http://www.ip138.com/ips8.asp"; Set up a URL to get the IP address and country source
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
String html = gethtml (URL); Get the source page
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); Get the country
ADR = GETADRBYIP (IP);
Return "IP:" + IP + "Country:" + Country + "Provinces and Cities:" + ADR;
}
#endregion

#region # #通过IP得到IP所在地省市
<summary>
IP location via IP (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 page
Regex reg = new Regex (REGSTR, regexoptions.none);
Match ma = Reg. Match (HTML);
html = ma. Value;
string[] arr = html. Split (")";
return arr[0];
}
#endregion

#region # #获取HTML源码信息
<summary>
Get HTML source information (Porschev)
</summary>
<param name= "url" > Get address </param>
<returns>html Source </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.