Python 분류
socket 이용
컨텐츠 정보
- 2,844 조회
- 0 추천
- 목록
본문
출처: https://twoicefish-secu.tistory.com/171
### 핵심 소스 코드
```
def nslookup(DOMAIN):
try:
ip_list = []
ais = socket.getaddrinfo(DOMAIN, 0, 0, 0, 0)
for result in ais:
ip_list.append(result[-1][0])
ip_list = list(set(ip_list))
return (',').join(ip_list)
except:
return "N/A"
```
### 전체 소스 코드
```
import os
import socket
from urllib.parse import urlparse
def nslookup(DOMAIN):
try:
ip_list = []
ais = socket.getaddrinfo(DOMAIN, 0, 0, 0, 0)
for result in ais:
ip_list.append(result[-1][0])
ip_list = list(set(ip_list))
return (',').join(ip_list)
except:
return "N/A"
def getDomain(PATH, FNAME):
# print PATH + '\\' + FNAME
with open(PATH + '\\' + FNAME, 'r') as f:
maldomain = f.readlines()
if len(maldomain) > 0:
for i in range(0, len(maldomain)):
# print i
if maldomain[i][:4] != "http":
maldomain[i] = "http://" + maldomain[i].rstrip()
# print urlparse(maldomain[i]).hostname
#maldomain[i] = "%-15s / %s" % (nslookup(urlparse(maldomain[i]).hostname), "hxxp" + maldomain[i][4:])
maldomain[i] = nslookup(urlparse(maldomain[i]).hostname)
print
maldomain[i]
else:
maldomain = "No URL in File"
## 결과 출력
# print maldomain
return maldomain
print
"Loading...."
result = open('result.txt', 'w')
for item in getDomain(os.getcwd(), "list.txt"):
result.write("%s\n" % item)
print
"Done. Thank you!"
```
관련자료
댓글 0
등록된 댓글이 없습니다.