import socket, os
list_dom = ['google.com', 'yahoo.com', 'bing.com']
for x in list_dom:
print('IP of domain: ' + x + socket.gethostbyname(x))
This Python code imports two modules, socket
and os
. The socket
module provides low-level network communications functionality, while os
provides a way to interact with the operating system.
The code defines a list of domains called list_dom
, which includes google.com
, yahoo.com
, and bing.com
.
The code then iterates over each domain in the list using a for
loop. Within the loop, the IP address associated with the current domain is obtained using the socket.gethostbyname()
method. This method takes a domain name as an argument and returns the IP address that corresponds to that domain.
The code then concatenates the string "IP of domain:" with the current domain name and its corresponding IP address, which is printed to the console.
This code retrieves the IP addresses associated with a list of domains and prints them to the console.
import socket, os
os.system('cls')
while True:
dom = input('Enter domain: ')
print(socket.gethostbyname(dom))
if dom == 'q':
print('Done ')
break
This Python code imports the 'socket' and 'os' modules. The 'socket' module provides a way to access the network and communicate with other computers through various socket types such as TCP and UDP. The 'os' module provides a way to interact with the underlying operating system, for example by calling system functions or clearing the console.
The code clears the console using the 'os' module. Then it enters an infinite loop, prompting the user to enter a domain name to be resolved to an IP address. The 'input' function reads the user's input as a string and stores it in the 'dom' variable.
The 'socket.gethostbyname' function is called with the 'dom' variable as an argument. This function returns the IP address associated with the specified domain name. The IP address is printed to the console using the 'print' function.
The code then checks if the user entered 'q' to quit. If the user entered 'q', the loop is broken and the code exits. Otherwise, the loop continues and prompts the user for another domain name to resolve.
Overall, this code allows the user to easily resolve domain names to IP addresses using the 'socket' module and provides a simple user interface for repeated lookups.
No comments:
Post a Comment