프로그램/python

[python] IP 후이즈(whois) 조회하기

더월드 2022. 11. 11.

한국인터넷진흥원(KISA)에서는 IP에 대한 할당 정보 검색 서비스를 제공합니다.

http://kisa.whois.or.kr

 

 

이런 IP 후이즈 조회를 파이썬으로 할 수는 없을까요?

아래와 같은 코드를 이용하면 충분이 가능합니다.

 

조금 수정하면 대량으로 IP 조회나 csv 파일을 읽어서 IP 조회가 가능합니다. ^^

#!/usr/bin/env python
# -*- coding: utf8 -*-
from ipwhois import IPWhois

def whois_lookup(ip):
    """Perform Whois lookup for a given IP
        :ip: Ip to peform whois lookup
    """
    #colors.info('Performing WHOIS lookup')
    obj = IPWhois(ip)
    response = obj.lookup_whois()
    details = response['nets'][0]
    #return {'Name': name, 'City': city, 'State': state, 'Country': country, 'address': address, 'description': description}
    return details

#--------------------------
# Main
#--------------------------
if __name__ == "__main__":
    
    ip ="223.130.200.107"
    ip_result=whois_lookup(ip)
    #print(ip_result)
    print("name = {0}".format(ip_result['name']))
    print("city = {0}".format(ip_result['city']))
    print("state = {0}".format(ip_result['state']))
    print("country = {0}".format(ip_result['country']))
    print("address = {0}".format(ip_result['address']))
    print("description = {0}".format(ip_result['description']))

 

위 코드를 실행한 결과 입니다.

댓글

💲 추천 글