Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python parse /etc/resolv.conf

def get_resolvers() -> str:
    """
    if using WSL will access /etc/resolv.conf and parse the host address
    :return: str ip address
    """
    resolvers = []
    try:
        with open("/etc/resolv.conf", encoding='utf-8') as resolvconf:
            for line in resolvconf.readlines():
                line = line.split('#', 1)[0].rstrip()
        if 'nameserver' in line:
            resolvers.append(line.split()[1])
        return resolvers[0] if len(resolvers) > 0 else "127.0.0.1"
    except Exception as err:
        return "127.0.0.1"
Comment

PREVIOUS NEXT
Code Example
Python :: Use the "map" function to find all the odd numbers and the even numbers in the list. Print 0 for odd and 1 for even. in python 
Python :: smote on dataframe of feature 
Python :: convert pdf to excel python 
Python :: create a thumbnail from video python 
Python :: changing database of django 
Python :: dictionary python 
Python :: python print main arguments 
Python :: concat Pandas Dataframe with Numpy array. 
Python :: python get chars among quotation marks 
Python :: Access python http.server on google colab 
Python :: Returns a DataFrame representing the result of the given query 
Python :: python float to int 
Python :: how to get all distinct substrings in a string python 
Python :: How can i restrict letters after a number in an input in Python 
Python :: git clone in python to tmp directory 
Python :: python tabulate without index 
Python :: python raise exception with custom message 
Python :: s=0 def sum(x,y): n=int(input("enter no. of terms") for i in range(n): l=int(input("enter no.")) s=s+l print(s) sum() 
Python :: sort np list of string 
Python :: fillna pandas inplace 
Python :: How to go up in a path in python 
Python :: python timedelta get days with fraction 
Python :: lru cache 
Python :: plt grid linestyles options 
Python :: create smtp server python 
Python :: get output of a function in a variable python 
Python :: python list sum 
Python :: no exception message supplied django template 
Python :: python sound 
Python :: Write a simple python program that adds 2 numbers togethe 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =