Winform-根据当前IP获取所在城市名称
来源:互联网 发布:灵族女捏脸数据图 编辑:程序博客网 时间:2024/05/21 19:32
利用到天气预报的WebService,代码如下:
public partial class frmMain : Form { WeatherWebService we; IpAddressSearchWebService we1; public frmMain() { InitializeComponent(); } private void frmMain_Load(object sender, EventArgs e) { try { we = new WeatherWebService(); we1 = new IpAddressSearchWebService(); string locality = we1.getCountryCityByIp(GetIP())[1]; string city = locality.Substring(locality.IndexOf('省') + 1, locality.IndexOf('市') - (locality.IndexOf('省') + 1)); WeatherShow(we.getWeatherbyCityName(city)); } catch (System.Exception ex) { } } private void WeatherShow(string[] strWeather) { labelTitle.Text = string.Format(strWeather[1]); } public static string GetIP() { using (var webClient = new WebClient()) { try { var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp"); var ip = Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value; return !string.IsNullOrEmpty(ip) ? ip : null; } catch (Exception ex) { return ex.Message; } } } }
效果如图:
源代码下载
0 0
- Winform-根据当前IP获取所在城市名称
- 根据IP地址获取所在城市
- 根据IP地址获取所在城市
- 根据ip获取所在城市信息
- 根据IP地址获取所在城市
- php 根据ip获取所在城市
- 根据IP获取IP所在城市PHP
- ip获取所在城市名称接口-PHP
- ip获取所在城市名称接口-JAVA
- PHP:根据IP地址获取所在城市
- PHP根据IP地址获取所在城市
- 根据IP地址获取所在城市信息
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- js根据ip地址获取所在城市
- 共享内存
- Linux内存查看命令
- 51单片机实现scanf和printf函数
- C++多线程
- Android测试原理(三)——使用Eclipse的ADT进行测试
- Winform-根据当前IP获取所在城市名称
- 实现圆角imageview
- Mybatis分页插件
- 网站项目必备——12款经典的白富美型 jQuery 图片轮播插件
- 九度OJ 1446 Head of a Gang
- 解决IE8弹出开发人员工具的方法
- UIScrollView实现循环滚动---快捷方式
- MapReduce实现大矩阵乘法及代码实现
- hdu 1159 最长公共子序列问题