728x90
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
'기타' 카테고리의 다른 글
[Mac] parallels desktop command-line (0) | 2022.08.22 |
---|---|
[Mac] Parallels Desktop에서 Vagrant를 사용하는 방법 (0) | 2022.08.22 |
[python] tcp 소켓 통신 (0) | 2022.08.19 |
[python] udp 소켓 통신 (0) | 2022.08.19 |
[기타] 2022년 Gartner 최고의 전략적 기술 동향 (0) | 2022.08.17 |