-
C#教程之IPIP.net识别客户端真实访问地址,具体到国家,省,市
本站最新发布 C#从入门到精通
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
这个IP库实测还是比较准确的,免费版的可以具体到国内城市,国外只能到国家名称,免费版的自己定期更新Ip数据库即可。
以下为C#调用代码
class Program
{
static void Main(string[] args)
{
try
{
//传入要查询的ip 和17monipdb.datx 下载的ip库所在位置
string address = IPAddress.FindIPAddress("1.198.219.205", @"D:\开发资料\资料\Code\IP地址获取\IPAddress\IPAddress\bin\Debug");
Console.WriteLine(address);
}
catch (IOException ioex)
{
Console.WriteLine(ioex.StackTrace);
}
catch (IPv4FormatException ipex)
{
Console.WriteLine(ipex.StackTrace);
}
Console.ReadKey(true);
}
}
public class IPAddress
{
public static string FindIPAddress(string ip,string basePath)
{
string address = "";
if (string.IsNullOrEmpty(ip))
{
return address;
}
try
{
string path = string.Format("{0}\\{1}", basePath, "17monipdb.datx");
City city = new City(path);
string[] arr = city.find(ip);
if (arr != null && arr.Length > 0)
{
address = string.Join("-", arr);
}
}
catch (IOException ioex)
{
Console.WriteLine(ioex.StackTrace);
}
catch (IPv4FormatException ipex)
{
Console.WriteLine(ipex.StackTrace);
}
return address.TrimEnd("-".ToCharArray());
}
}
IPIP.net官网在这 戳戳戳
————————————————
版权声明:本文为CSDN博主「皮皮虾大侠」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Asa_Jim/article/details/94394612 是本人CSDN原创
栏目列表
最新更新
文件操作如何进制逐行读取
Python相对路径
with创建临时运行环境
Python文件操作
机器学习实战:基于Scikit-Learn和TensorFlow 读
Python爬虫--喜马拉雅三国音频爬取
Python爬虫之cookie的获取、保存和使用【新
Pyhton表白代码——浪漫圣诞节
Python连载57- 邮件头和主题、解析邮件
django自带的contentType表
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
mysql 安装了最新版本8.x版本后的报错:
Mysql空间数据&空间索引(spatial)
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能
将Session值储存于SQL Server中