import binascii
from scapy.all import *
import socket

def action(host,port):
	output={}
	cotp=binascii.unhexlify('0300001611e00000001400c1020100c2020102c0010a')
	alt_COTP = binascii.unhexlify("0300001611e00000000500c1020100c2020200c0010a")
	ROSCTR_Setup = binascii.unhexlify("0300001902f08032010000000000080000f0000001000101e0")
	Read_SZL = binascii.unhexlify("0300002102f080320700000000000800080001120411440100ff09000400110001")
	first_SZL_Request = binascii.unhexlify("0300002102f080320700000000000800080001120411440100ff09000400110001")
	second_SZL_Request = binascii.unhexlify("0300002102f080320700000000000800080001120411440100ff090004001c0001")
	response=None
	pkt = Ether(cotp)
	MESSAGE = pkt
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	try:
		s.settimeout(3)
		s.connect((host,port))
	except:
		return False
	response=send_receive(s,cotp)
	if(response):
		if(hex(response[5])!="0xd0"):
			s.close()
			s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			s.connect((host,port))
			response=send_receive(s,alt_COTP)
			if(response):
				if(hex(response[5])!="0xd0"):
					return False
	response  = send_receive(s,ROSCTR_Setup)
	if(response):
		if(hex(response[7])!="0x32"):
			return False
	response  = send_receive(s,Read_SZL)
	if(response):
		if(hex(response[7])!="0x32"):
			return False
	response  = send_receive(s, first_SZL_Request)
	try:
		output = first_parse_response(response,output)
	except:
		return False
	response = send_receive(s, second_SZL_Request)
	output=second_parse_response(response,output)
	output["DeviceIP"]=host
	output["Port"]=port
	return output