|
源码很简单,,,回复下查看吧,,,,
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Windows.Forms;
- namespace 取本机IP
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- string url = "http://iframe.ip138.com/ic.asp";
- WebClient Http = new WebClient();
- Http.Proxy = null;//不设置代理的话,建议把这句都加上
- string result = Http.DownloadString(new Uri(url));
- string mid = GetMid(result, "您的IP是:[", "</center>");
- MessageBox.Show("您的IP是:[" + mid);
- }
- private string GetMid(string all, string r, string l)
- {
- int rn = all.IndexOf(r) + r.Length;
- int ln = all.IndexOf(l, rn);
- return all.Substring(rn, ln - rn);
- }
- }
- }
复制代码 |
|