A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4698

Backtrace:

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 693
Function: getPaste

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once

Re: Traceroute in python - Stikked
From asdf, 8 Years ago, written in Python.
This paste is a reply to Traceroute in python from Jessica - go back
Embed
Viewing differences between Traceroute in python and Re: Traceroute in python
import socket
import sys

class TraceRoute(object):
    
    BADDR = "0.0.0.0" # default bind address - (all IPs)
    PORT = 33434 # default port
    ICMP = socket.getprotobyname('icmp')
    UDP = socket.getprotobyname('udp')

    desternation = ""
    ttl = 0 # we inrecement this by one each time.    

    # sockets
    reciever = None
    sender = None

    # finished?
    finished = False

    def __init__(self, desternation):
        self.desternation = socket.gethostbyname(desternation)
        
        self.reciever = socket.socket(socket.AF_INET, socket.SOCK_RAW, self.ICMP)
        self.sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, self.UDP)
        
        # bind to reciever so we can listen for replies
        self.reciever.bind((self.BADDR, self.PORT))

    def next_server(self):
        """ Connects to next server 1 hop away from current server (i.e. server[ttl + 1]) """
        if self.finished:
            # we have nothing to do, just return
            return

        # first job increment the ttl on the socket
        self.ttl += 1
        self.sender.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
        
        self.sender.sendto("", (self.desternation, self.PORT))
        current_server = self.reciever.recvfrom(512)[1][0] # get 512 bytes from the reciever 
        self.display(current_server)

        if current_server == self.desternation:
            self.finished = True

    def display(self, address):
        """ Gets the hostname (if we can) and displays """
        try:
            name = socket.gethostbyaddr(address)[0]
            print "%s) %s (%s)" % (self.ttl, name, address)
        except socket.error:
            # we couldn't - we'll just tell them the IP address
            print "%s) %s" % (self.ttl, address)
        
    def __del__(self):
        """ Be good and close our sockets """
        try:
            self.reciever.close()
        except socket.error:
            # already closed
            pass

        try:
            self.sender.close()
        except socket.error:
            # already closed
            pass

if __name__ == "__main__":
    # lets get the address from the commandline args
    if len(sys.argv) <= 1:
        # nothing been specified
        print "You need to give an address"
        print "%s <server>" % sys.argv[0]
        sys.exit() # we can't do anything.
    
    tracert = TraceRoute(sys.argv[1])
    while not tracert.finished:
        tracert.next_server()