나는 나의 /etc/hosts
파일에/etc/hosts에서 IP 주소를 얻는 방법은 무엇입니까?
54.230.202.149 gs2.ww.prod.dl.playstation.net
의 /etc/hosts
파일의 라인 gs2
을 찾아 현재의 IP 주소를 얻을 수를 다음 줄을 가지고있다. 이것은 내가 가지고있는 것이지만 DNS를 찾거나 IP 주소를 반환하지 않습니다. 현재 IP 주소가 '없음'이라고 나와 있습니다.
try:
with open('/etc/hosts', 'r') as f:
for line in f:
host_ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b.+(?=gs2)", line)
if host_ip:
current_ip = host_ip[0].strip()
else:
current_ip = 'None'
except:
current_ip = 'Unknown'
c.execute('INTERT INTO status VALUES(?,?,?,?,?,?)',
('Current Configured IP', current_ip))
무엇이 문제인지 잘 모릅니다. 어떤 도움을 주시면 감사하겠습니다.
내 대답이 'gs2'계정으로 업데이트되고 해당 문자열에 적절한 색인이 제공됩니다. –