Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
python help please understanding the code?
!/usr/bin/env python
from socket import *
if __name__ == '__main__':
target = raw_input('Enter host to scan: ')
targetIP = gethostbyname(target)
print 'Starting scan on host ', targetIP
#scan reserved ports
for i in range(20, 1025):
s = socket(AF_INET, SOCK_STREAM)
result = s.connect_ex((targetIP, i))
if(result == 0) :
print 'Port %d: OPEN' % (i,)
s.close()
i just took this code from the internet to scan for open ports, i put into python idle the code run fine but i dont understand the code, i can understand the output is pretty clear but i cant understand the code
this is the output:
Enter host to scan: localhost
Starting scan on host 127.0.0.1
Port 135: OPEN
Port 445: OPEN
can anyone explain this code for me please
how could i put coments to understand this code better?
thanks
2 Answers
- Anonymous8 years agoFavorite Answer
Searching for the local host to determine the ports here: Enter host to scan: localhost
Starting scan on host 127.0.0.1
Port 135: OPEN
Port 445: OPEN
- ?Lv 45 years ago
I don't use python, so i'm not definite of the distinct syntax.. The entire factor looks to be the of a longer pursuits; the first four strains show up to define a variable & square / dice operations however will not be really used? The raw_input line appears to print a prompt and be given a text string. It appears that is supposed to be three numeric values separated by commas. The x_str.Break up line breaks the input textual content at the commas, so striking the three values in elements of an array. The variety() line is presumably to get the quantity of factors within the array, or instantiate the variable x ?? Not fairly sure on that. The for line then walks by way of the array, and for each and every aspect the next line takes the numeric worth of one of the most string or text formatted numbers from the input array. It should turn out to be with the factors of the array x[] having the numbers the person enter at the immediate line; if the user follows the recommendations and entered three values separated with the aid of commas, three elements of the array would hold these values.