dongmou3615 2010-10-24 07:49
浏览 49
已采纳

我想检查IP地址到相应的主机名和主机名IP范围

I need to make it with PHP, maybe with some pear package or php internal functions. How i can do that ?

I know i need gethostbyname() for hostname checking, but i need also ip range of this provider. example: ip: 5.7.8.9 host: usa provider ip range 5.7.8.0-5.7.9.0

Is it possible with php?

  • 写回答

1条回答 默认 最新

  • doulu1914 2010-10-24 08:23
    关注

    There's no way to accurately see IP ranges without access to BGP, but if you trust the ISPs to provide the correct information you can get it from whois. Use shell_exec or similar to call the command-line whois client.

    I propose you heck for these labels:

    • inetnum
    • NetRange
    • CIDR
    • route

    And possibly more. Whois is however not always trustworthy. It's a text database with no defined standard format, so you may not always get a usable answer, and you don't always know what to look for.

    As I said, the most trustworthy solution is to get real BGP access so you can check actual Internet routing. This is however rather advanced, so maybe there is some web service you can use for routing lookups?

    Edit I actually found this project, which provides an API for BGP queries: http://www.routeviews.org/

    There are two sub-domains of TXT reconds in routeviews.org, asn and aspath. asn.routeviews.org maps (resolves) a reversed IPv4 address or prefix (eg: 128.223 -> 223.128.asn.routeviews.org) to the origin AS (and prefix and prefix length) of the best route as seen by route-views2.routeviews.org. aspath.routeviews.org is the same idea, but resolves to the full AS path.

    This can possibly be used for getting the subnet of an IP through simple DNS queries. Whit the subnet it's easy to calculate the IP range (as you probably already know, the range is just a different notation of the subnet).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错