-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnmap.py
89 lines (57 loc) · 1.88 KB
/
nmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
#-*- coding:utf-8 -*-
try:
import nmap
import re
import os
import argparse
import urllib2
except ImportError,e:
import sys
sys.stdout.write("%s\n" %e)
sys.exit(1)
class Tarama:
def __init__(self):
self.cmd_arg = "-n -Pn -sS -sV -T4 --top-ports 10"
self.nmap_services_file = "/usr/share/nmap/nmap-services"
self.nm = nmap.PortScanner()
def get_service_name(self, port, proto):
nmap_file = open(self.nmap_services_file,"r")
service = ""
for line in nmap_file:
if re.search("([^\s]+)\s%d/%s\s"% (port, proto), line):
service = re.search("([^\s]+)\s%d/%s\s"% (port, proto), line).groups(1)[0]
break
return service
def run_scan(self,targets):
self.nm.scan(hosts = "%s"% targets, arguments = "%s"% self.cmd_arg)
for host in self.nm.all_hosts():
print "IP i ADRESİNİZ",host
print "\n"
print("PORT STATE SERVICE")
for proto in self.nm[host].all_protocols():
result = self.nm[host][proto].keys()
result.sort()
for port in result:
res = str(port) + "/" + proto
space = str(" " * (9 - len(res)))
service = self.get_service_name(port, proto)
state = self.nm[host][proto][port]['state']
space2 = str(" " * (10 - len(state)))
print "%s/%s%s%s%s%s" % (port,proto,space,state,space2,service)
print "Adresi girerken başına www. Kullanmayınız."
domain_name = raw_input("Domain adresi=")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Nmap Ile Port Tarama Programi')
try:
tarama = Tarama()
tarama.run_scan(domain_name)
except Exception, e:
print >> sys.stderr, "Hata: %s"% e
sys.exit(2)
#HTTP FINGERPRINTING SCRIPT
print(" \n \n ***** HTTP Banner Grabbing ***** \n")
remoteServer2="http://www."+domain_name
c = urllib2.urlopen(remoteServer2)
print c.info()
print c.getcode()