向对应的whois服务器,即rir机构,请求IP的详细whois信息

RIR_WHOIS = {
‘arin’: {‘server’: ‘whois.arin.net’},
‘lacnic’:{‘server’: ‘whois.lacnic.net’},
‘ripe’: {‘server’: ‘whois.ripe.net’},
‘apnic’: {‘server’: ‘whois.apnic.net’},
‘afrinic’: {‘server’: ‘whois.afrinic.net’}
}
RIRS = [“arin”,“lacnic”,“ripe”,“apnic”,“afrinic”]

def get_whois(rir,query_ip):
    '''
    功能: 向对应的whois服务器,即rir机构,请求IP的详细whois信息
    return:返回对应的whois信息
    '''
    global RIR_WHOIS
    response = ''
    error_whois = ''
    if rir == "ripencc":
        rir = "ripe"
    if rir in RIRS:
        try:

            '''
            功能: 根据rir,获取query_ip的whois信息
            return: 返回查询所得的whois信息
            '''
            server = RIR_WHOIS[rir]['server']
            # Create the connection for the whois query.

            conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            conn.settimeout(10)
            conn.connect((server, 43))
            # Prep the query.
            query = query_ip + '\r\n'

            conn.send(query.encode())
            while True:
                try:
                    d = conn.recv(4096).decode('ascii', 'ignore')
                    response += d
                    if not d:
                        break

                except Exception as e:
                    '''error: [Errno 104] Connection reset by peer'''
                    error_whois = str(e)
                    conn.settimeout(3)
                    d = conn.recv(4096).decode('ascii', 'ignore')
            conn.close()
            # parse_whois_q.put([ip_as, response])

        except Exception as e:
            error_whois = str(e)
            # get_whois_q.put([ip_as, rir, query_ip])
    else:
        if rir == "":
            error_whois = 'as get error: '
        else:
            error_whois = 'rir is not exits'
    return (response, error_whois)

获得的各个字段的意思如下:
inetnum:inetnum对象描述的IP地址空间范围。
netnam:IP地址空间范围的名称。
descr:分配或分配了inetnum中显示的地址空间的组织的说明。
country:admin-c所在国家或经济体的两个字母的ISO 3166代码。
请使用大写字母。
admin-c:现场联系人“person”对象的NIC句柄。由于不止一个人经常履行一个角色职能,因此可能会列出多个admin-c。

admin-c:在web界面中,admin-c属性包含指向NIC句柄所属的“person”对象的链接。
管理联系人(admin-c)必须是实际位于网络站点的人员。

tech-c:tech-c技术联系人“person”或“role”对象的NIC句柄。由于不止一个人经常履行一个角色职能,因此可能会列出不止一个tech-c。
在web界面中,tech-c属性包含指向NIC句柄所属的“person”或“role”对象的链接。
技术联系人(tech-c)必须是负责网络日常运行的人员,但不需要实际位于网络站点。
status:APNIC Whois数据库下的所有inetnum对象都必须具有status属性。status属性必须是以下值之一:
状态定义
分配
便携式
设定值:仅限APNIC/NIR
APNIC或NIR分配给LIR的地址空间,以便LIR随后分配给其客户。如果网络更改上游提供程序,则这些分配仍然有效。
分配
不可携带
值设置者:LIR/ISP
由LIR分配给客户的地址空间,供这些客户后续分配。如果网络更改上游提供程序,则必须返回这些分配(以及从这些分配中进行的分配)。
分配
便携式
设定值:仅限APNIC/NIR
由APNIC或NIR进行的分配,例如,小型多点分配或IXP分配。如果网络更改上游提供程序,则这些分配仍然有效。
分配
不可携带
值设置者:LIR/ISP
LIR为其客户在其运营的互联网基础设施中的特定用途而向其分配的任务。分配只能用于特定的、记录在案的目的,不得再进行分配;如果网络更改了上游提供商,则必须返回这些分配
mnt-by:mnt by列出一个注册的“mntner”,用于授权和验证对此对象的更改。
“mntner”对象是用于授权APNIC数据库更新的数据库对象。
当数据库详细信息受“mntner”对象保护时,只有能够访问该“mntner”对象的安全信息的人员才能更改详细信息。
在web界面中,mnt by属性包含指向指定“mntner”的链接。
source注册对象的数据库。
对APNIC数据库中的对象使用APNIC。
请使用大写字母。

英文代码介绍如下:

Mandatory
Attribute must be included in the object. Failure to do so will result in errors.

Attribute Description
inetnum The range of IP address space described by the object.
netname The name of a range of IP address space.
descr Description of the organization allocated or assigned the address space shown in the inetnum.
country Two letter ISO 3166 code of the country or economy where the admin-c is based.
Please use UPPERCASE letters.

EXAMPLE
country: WF
admin-c The NIC-handle of an on-site contact ‘person’ object. As more than one person often fulfills a role function, there may be more than one admin-c listed.
In the web interface, the admin-c attribute contains a link to the ‘person‘ object the NIC-handle belongs to.
An administrative contact (admin-c) must be someone who is physically located at the site of the network.
tech-c The NIC-handle of a technical contact ‘person’ or ‘role’ object. As more than one person often fulfills a role function, there may be more than one tech-c listed.
In the web interface, the tech-c attribute contains a link to the ‘person’ or ‘role’ object to which the NIC-handle belongs to.
A technical contact (tech-c) must be a person responsible for the day-to-day operation of the network, but does not need to be physically located at the site of the network.
status All inetnum objects under APNIC Whois Database must have a status attribute. The status attribute must be one of the following values:
Status Definition
Allocated
Portable
Value set by: APNIC/NIR Only

Address space allocated by APNIC or NIRs to LIRs for the purpose of subsequent distribution by LIRs to their customers. These allocations remain valid if the network changes upstream provider.

Allocated
Non-Portable
Value set by: LIR/ISP

Address space allocated by LIRs to their customers for subsequent assignment by those customers. These allocations (and assignments made from these allocations) must be returned if the network changes upstream provider.

Assigned
Portable
Value set by: APNIC/NIR Only

Assignments made by APNIC or NIRs, for example, small multihoming assignments or IXP assignments. These assignments remain valid if the network changes upstream provider.

Assigned
Non-Portable
Value set by: LIR/ISP

Assignments made by LIRs to their customers for specific use within the Internet infrastructure they operate. Assignments must only be made for specific, documented purposes and may not be sub-assigned.; These assignments must be returned if the network changes upstream provider.

mnt-by Lists a registered ‘mntner’ used to authorize and authenticate changes to this object.
A ‘mntner’ object is a database object used to authorize updates to the APNIC database.
When your database details are protected by a ‘mntner’ object, then only persons with access to the security information of that ‘mntner’ object will be able to change details.
In the web interface, the mnt-by attribute contains a link to the specified ‘mntner’.
mnt-irt The identifier of a registered ‘mntner’ object used to provide information about a Computer Security Incident Response Team (CSIRT).
last-modified It is a time stamp that is generated by the system to reflect when the object was last modified.
last-modified: 2018-08-30T07:50:19Z
source The database where the object is registered.
Use APNIC for objects in the APNIC Database.
Please use UPPERCASE letters.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值