Beispiel #1
0
    def __tcpEstablishConnection(self, serverIp):
        """Establishes a TCP connection by doing a handshake with
           the server."""
        clientPort = random.randint(1025, 65530)

        # Sends a SYN message to establish connection
        segment = TcpSegment("", clientPort, self.ircPort)
        segment.setSYN()
        datagram = IpDatagram(segment, self.ipAddr, serverIp)
        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)
        packet = self.netQueue.get()

        # Receives packet containing server's SYN
        segment = TcpSegment("", clientPort, self.ircPort)
        segment.setAckNumber(packet.getSegment().getAckNumber())
        segment.setACK()
        segment.setSeqNumber(1)
        segment.setSeqNumber(1)
        datagram = IpDatagram(segment, self.ipAddr, packet.getOriginIp())
        self.netQueue.task_done()
        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)

        # Defines the randomized client port number
        self.application.setClientPort(clientPort)
Beispiel #2
0
    def __tcpEstablishConnection(self, serverIp):
        """Establishes a TCP connection by doing a handshake with
           the server."""
        clientPort = random.randint(1025, 65530)

        # Sends a SYN message to establish connection
        segment = TcpSegment("", clientPort, self.ircPort)
        segment.setSYN()
        datagram = IpDatagram(segment, self.ipAddr, serverIp)
        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)
        packet = self.netQueue.get()

        # Receives packet containing server's SYN
        segment = TcpSegment("", clientPort, self.ircPort)
        segment.setAckNumber(packet.getSegment().getAckNumber())
        segment.setACK()
        segment.setSeqNumber(1)
        segment.setSeqNumber(1)
        datagram = IpDatagram(segment, self.ipAddr, packet.getOriginIp())
        self.netQueue.task_done()
        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)

        # Defines the randomized client port number
        self.application.setClientPort(clientPort)
Beispiel #3
0
    def __dnsConnect(self, name):
        """Connects to the DNS server to obtain the given name's
           corresponding IP."""
        segment = UdpSegment(name, 2000, self.dnsPort)
        datagram = IpDatagram(segment, self.ipAddr, self.dnsAddr)
        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)
        packet = self.netQueue.get()

        ip = packet.getSegment().getMessage().split(',')[1]
        self.netQueue.task_done()
        return ip
Beispiel #4
0
    def __dnsConnect(self, name):
        """Connects to the DNS server to obtain the given name's
           corresponding IP."""
        segment = UdpSegment(name, 2000, self.dnsPort)
        datagram = IpDatagram(segment, self.ipAddr, self.dnsAddr)
        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)
        packet = self.netQueue.get()

        ip = packet.getSegment().getMessage().split(',')[1]
        self.netQueue.task_done()
        return ip
Beispiel #5
0
    def __tcpCloseConnection(self, finalPacket):
        """Close TCP connection by doing a handshake with
           the server."""
        serverIp = finalPacket.getDestinationIp()
        clientPort = finalPacket.getSegment().getOriginPort()

        # Sends a FIN/ACK message to close connection
        packet = self.netQueue.get()

        # Receives packet containing server's SYN
        segment = TcpSegment("", clientPort, self.ircPort)
        segment.setAckNumber(packet.getSegment().getAckNumber())
        segment.setACK()
        segment.setSeqNumber(packet.getSegment().getAckNumber())
        segment.setAckNumber(packet.getSegment().getSeqNumber() + 1)

        datagram = IpDatagram(segment, self.ipAddr, packet.getOriginIp())
        self.netQueue.task_done()

        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)
Beispiel #6
0
    def __tcpCloseConnection(self, finalPacket):
        """Close TCP connection by doing a handshake with
           the server."""
        serverIp = finalPacket.getDestinationIp()
        clientPort = finalPacket.getSegment().getOriginPort()

        # Sends a FIN/ACK message to close connection
        packet = self.netQueue.get()

        # Receives packet containing server's SYN
        segment = TcpSegment("", clientPort, self.ircPort)
        segment.setAckNumber(packet.getSegment().getAckNumber())
        segment.setACK()
        segment.setSeqNumber(packet.getSegment().getAckNumber())
        segment.setAckNumber(packet.getSegment().getSeqNumber() + 1)

        datagram = IpDatagram(segment, self.ipAddr, packet.getOriginIp())
        self.netQueue.task_done()

        datagram.setId(self.__nextPacketId())
        self.link.putTargetQueue(datagram)