반응형
python dns(hostname) 정보 확인
socket.gethostbyname : 도메인 이름에 대한 IP 주소를 반환
socket.gethostbyname('naver.com')
socket.gethostbyname_ex : 확장판(다른 이름의 리스트, 주소의 리스트를 반환)
socket.gethostbyname_ex('naver.com')
$ python
Python 3.9.13 (main, Aug 7 2022, 01:19:39)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyname('naver.com')
'223.130.200.107'
>>> socket.gethostbyname_ex('naver.com')
('naver.com', [], ['223.130.195.200', '223.130.195.95', '223.130.200.104', '223.130.200.107'])
>>>
한 줄로 python 실행
python -c "import socket; print(socket.gethostbyname_ex('sangchul.kr'))"
$ python -c "import socket; print(socket.gethostbyname_ex('sangchul.kr'))"
('sangchul.kr', [], ['27.0.236.139'])
$ python -c "import socket; print(socket.gethostbyname_ex('naver.com'))"
('naver.com', [], ['223.130.195.200', '223.130.195.95', '223.130.200.104', '223.130.200.107'])
$ python
Python 3.9.13 (main, Aug 7 2022, 01:19:39)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getaddrinfo('sangchul.kr', 80)
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('27.0.236.139', 80)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('27.0.236.139', 80))]
$ python -c "import socket; print(socket.getaddrinfo('sangchul.kr', 80))"
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('27.0.236.139', 80)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('27.0.236.139', 80))]
728x90
반응형
'기타' 카테고리의 다른 글
[제품] ipTIME AX2004BCM 유무선공유기 (0) | 2022.11.01 |
---|---|
mypage (0) | 2022.10.20 |
[python] tcp 소켓 통신 (0) | 2022.08.19 |
[python] udp 소켓 통신 (0) | 2022.08.19 |
[집체교육] DevOps를 위한 IaC 클라우드 인프라 자동화 전문가 과정 (0) | 2022.08.19 |