Get Host IP Address Function

  • Share this:

Code introduction


This function is used to get the IP address of a specified host. If the hostname cannot be resolved, it returns None.


Technology Stack : socket

Code Type : Network programming

Code Difficulty : Intermediate


                
                    
import math
import os
import random
import re
import socket
import sys

def find_ip_address(host):
    """
    获取指定主机的IP地址
    """
    try:
        return socket.gethostbyname(host)
    except socket.gaierror:
        return None                
              
Tags: