5
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by SoulMazer
Featured Replies
  • if you know how to do it from CLI then try subprocess Read More

  • If you're just doing this for yourself and are not too concerned about efficiency, this should suffice: [code=python]from socket import * if __name__ == '__main__': target = "localhost" targetIP = gethostbyname(target) print 'Starting scan on host ', targetIP #scan reserved ports for i in range(20, 1025): s = socket(AF_INET, SOCK_STREAM) … Read More

  • I'm not sure this is possible, but I have had some results with the following: [code=python]port = 80 proto = getservbyport(portnum) print proto[/code] I'm not quite sure why it returns "www", I would expect "http", but maybe Python has a way of translating it. You might have to research it … Read More

0

Do you know how to do it in any other language?

I know this can be done by a command in *nix systems called nmap, i just need to do it in python, and it to be cross platform to lindows.

0

if you know how to do it from CLI then try subprocess

Thanks for the reply,
I only know how to do it in linux using nmap, any ideas on windows?

1

If you're just doing this for yourself and are not too concerned about efficiency, this should suffice:

from socket import * 

if __name__ == '__main__':
	target = "localhost"
	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()

You could always consult Wikipedia's reserved port list to tell what service a user is most likely running.

Also, if you are interested in efficiency (by means of threading), just post back and I'll give you some more code.

Edited by SoulMazer: More information

0

I know this can be done by a command in *nix systems called nmap, i just need to do it in python, and it to be cross platform to lindows.

Question sustains.
Do you have a particular problem with python, or do you need help to understand portmapping in general?

Edited by nezachem: n/a

0

Clarification: I know how to check what ports are open, I just need a way to know what service a port is running, like ftp, i have a script like SoulMazer posted, I was just hoping there was a better way of identifying what a port is running, like HTTP or FTP rather than checking the port against a list.

1

I'm not sure this is possible, but I have had some results with the following:

port = 80
proto = getservbyport(portnum)
print proto

I'm not quite sure why it returns "www", I would expect "http", but maybe Python has a way of translating it. You might have to research it yourself, but I hope this is a help.

Votes + Comments
This is exactly what I needed.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.