User:Plume: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Plume (talk | contribs)
Created page with '=Skriptimiskeeled Quest 2= <source lang="python"> #!/usr/bin/python # -*- coding: utf-8 -*- # Autor: Priit Lume # Ryhm: Ak51 # Skript kontrollib argumendina antava ipv4 aadress…'
 
Plume (talk | contribs)
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Autor: Priit Lume
# Autor: Priit Lume
# Ryhm: Ak51
# Ryhm: AK51
# Skript kontrollib argumendina antava  ipv4 aadressi lahtiseid
# Skript kontrollib argumendina antava  ipv4 aadressi lahtiseid
# porte. Kontrollitavad pordid v6etakse teise argumendina antavast
# porte. Kontrollitavad pordid v6etakse teise argumendina antavast
Line 61: Line 61:


#Ylej22nud portide kontroll
#Ylej22nud portide kontroll
for port in range(1, 23):
for port in range(1, 10001):
     if port in check_ports:
     if port in check_ports:
         continue
         continue

Latest revision as of 10:18, 2 February 2013

Skriptimiskeeled Quest 2

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Autor: Priit Lume
# Ryhm: AK51
# Skript kontrollib argumendina antava  ipv4 aadressi lahtiseid
# porte. Kontrollitavad pordid v6etakse teise argumendina antavast
# failist, kus need peavad paiknema yhekaupa eraldi ridadel. 
# Litsentsinfo: Skript on koostatud IT Kolledzhi aine 
# skriptimiskeeled arvestust88ks. Autor ei sea piiranguid selle 
# kasutamiseks va. skripti esitamine hindamiseks enda nime alt. 
# versioon 0.2 (02.02.2013)

from sys import argv
from socket import *  

#Argumentide arvu kontroll
if len(argv) != 3:
	print 'Peab olema 2 argumenti - ip aadress ja failinimi'
	exit(3)
#Muutujad
addr = argv[1]
fail = argv[2]
check_ports = []
open_ports = []

#ip aadressi kontroll
try:
    inet_aton(addr)
except IOError, err:
    print 'Pole korrektne ip aadress'
    exit(4)
#faili olemasolu ja lugemis6iguse kontroll
try:
    open(fail, 'r').read()
except IOError, err:
    print 'IOError: ', err
#Failist portide lugemine ja korrastamine
with open(fail, 'r') as (f):
    for i in f.read().split():
        check_ports.append(int(i))
    f.close()
check_ports.sort()

print 'Kontollin aadressil %s porte %s' % (addr, check_ports)
for port in check_ports:    
    s = socket(AF_INET, SOCK_STREAM)
    if s.connect_ex((addr, port)) == 0:
        open_ports.append(port)
    s.close()

if len(open_ports) == 0:
    print 'Ykski ette antud portidest pole lahti'
    exit(2)

if len(open_ports) < len(check_ports):
    print 'M6ni ette antud portidest on kinni'
    exit(2)

#Ylej22nud portide kontroll
for port in range(1, 10001):
    if port in check_ports:
        continue
    s = socket(AF_INET, SOCK_STREAM)
    if s.connect_ex((addr, port)) == 0:
        print 'Peale ette antud pordide on veel lahtiseid porte'
        exit(1)
    s.close()
 
if open_ports == check_ports:
    print 'Vaid ette antud pordid on lahti'
    exit(0)