I have a text file contains domains and IPs, I want to get the IP using the domain name but it returns null.
Here is my code:
import json
import os
import sys
import pathlib
import platform
HERE = pathlib.Path(__file__).parent
def clean_server_names(name):
server_names_list = [x.lower().strip() for x in
open(HERE / "servers" / "myservers.txt", 'r').readlines()]
for server in server_names_list:
domain_name_and_code = server.split(' ')
domain = domain_name_and_code[0].strip()
ip = domain_name_and_code[-1].strip()
if name == domain:
print(ip)
clean_server_names("domain1.nordvpn.com ")
Here's what inside my text file.
domain1.nordvpn.com 192.168.1.1
if name == domain:how is thenameinitialized ? name still containsdomain1.nordvpn.com 192.168.1.1. so equal will not work.clean_server_names("domain1.nordvpn.com ")see the last space after .com. so you can either remove space when you pass the parameter or strip the space ` if name.strip() == domain:`