C#使用有道ip地址查询接口方法实例详解
作者:陌香 时间:2022-10-08 22:07:31
本文实例讲述了C#使用有道ip地址查询接口方法。分享给大家供大家参考。具体实现方法如下:
#region 读取http://www.yodao.com接口IP地址
/// <summary>
/// 读取http://www.yodao.com接口IP地址
/// </summary>
public static string GetstringIpAddress(string strIP)//strIP为IP
{
string sURL = "http://www.youdao.com/smartresult-xml/search.s?type=ip&q="+strIP+"";
//youdao的URL
string stringIpAddress = "";
using (XmlReader read = XmlReader.Create(sURL))
//获取youdao返回的xml格式文件内容
{
while (read.Read())
{
switch (read.NodeType)
{
case XmlNodeType.Text://取xml格式文件当中的文本内容
if (string.Format("{0}", read.Value).ToString().Trim() != strIP)
//youdao返回的xml格式文件内容一个是IP,
//另一个是IP地址,如果不是IP那么就是IP地址
{
stringIpAddress=string.Format("{0}", read.Value).ToString().Trim();//赋值
}
break;
//other
}
}
}
return stringIpAddress;
}
返回的xml数据格式:
<?xml version="1.0" encoding="gbk" ?>
<smartresult>
<product type="ip">
<ip>60.223.233.226</ip>
<location>山西省朔州市 网通</location>
</product>
</smartresult>
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,ip地址
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
git自定义_动力节点Java学院整理
2021-06-11 22:05:49
![](https://img.aspxhome.com/file/2023/9/94349_0s.jpg)
C#双缓冲实现方法(可防止闪屏)
2021-07-07 18:15:33
Java日期操作类常见用法示例
2021-06-17 01:12:59
java开发之MD5加密算法的实现
2022-05-13 23:44:35
java虚拟机中多线程总结
2022-09-01 22:55:48
![](https://img.aspxhome.com/file/2023/6/79956_0s.png)
java String的intern方法
2021-07-05 03:23:52
SpringBoot打成war包在tomcat或wildfly下运行的方法
2023-11-23 08:20:56
android全局监控click事件的四种方式(小结)
2023-05-02 07:33:31
Mybatis SqlSessionFactory与SqlSession详细讲解
2021-12-24 22:42:56
![](https://img.aspxhome.com/file/2023/6/62086_0s.png)
Java实现简单LRU缓存机制的方法
2023-08-11 03:54:49
![](https://img.aspxhome.com/file/2023/7/83057_0s.png)
Java线程池的优点及池化技术的应用
2022-07-01 08:12:23
![](https://img.aspxhome.com/file/2023/0/72290_0s.webp)
Flutter加载图片流程之ImageProvider源码示例解析
2021-07-19 05:05:19
java和 javaw 及 javaws的区别解析
2023-07-21 06:31:05
![](https://img.aspxhome.com/file/2023/9/64749_0s.png)
java增强for循环的实现方法
2023-12-07 16:42:53
分享C#操作内存读写方法的主要实现代码
2022-10-08 08:08:44
@NonNull导致无法序列化的问题及解决
2021-07-21 23:07:33
![](https://img.aspxhome.com/file/2023/2/103852_0s.png)
python只需30行代码就能记录键盘的一举一动
2023-06-27 18:22:12
![](https://img.aspxhome.com/file/2023/3/82403_0s.gif)
java 实现KMP算法
2022-09-14 15:44:40
![](https://img.aspxhome.com/file/2023/4/83104_0s.gif)
Mybatis中的mapper模糊查询语句LIKE
2022-02-17 16:21:15
android多媒体类VideoView使用方法详解
2023-12-12 03:37:47
![](https://img.aspxhome.com/file/2023/6/89516_0s.jpg)