omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    trace route script

    Pythonista
    2
    9
    4481
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • hallaste
      hallaste last edited by

      Simple trace route script fails in Pythonista, but works well in Python 2.7.5.

      import socket

      def main(dest_name):
      dest_addr = socket.gethostbyname(dest_name)
      port = 33434
      max_hops = 30
      icmp = socket.getprotobyname('icmp')
      udp = socket.getprotobyname('udp')
      ttl = 1
      while True:
      # error [Errno 1] Operation not permitted
      recv_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
      send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
      send_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
      recv_socket.bind(("", port))
      send_socket.sendto("", (dest_name, port))
      curr_addr = None
      curr_name = None
      try:

      1 Reply Last reply Reply Quote 0
      • filippocld223
        filippocld223 last edited by

        can you correctly format the script?

        1 Reply Last reply Reply Quote 0
        • hallaste
          hallaste last edited by

          import socket
          
          def main(dest_name):
              dest_addr = socket.gethostbyname(dest_name)
              port = 33434
              max_hops = 30
              icmp = socket.getprotobyname('icmp')
              udp = socket.getprotobyname('udp')
              ttl = 1
              while True:
                  recv_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
                  send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
                  send_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
                  recv_socket.bind(("", port))
                  send_socket.sendto("", (dest_name, port))
                  curr_addr = None
                  curr_name = None
                  try:
                      _, curr_addr = recv_socket.recvfrom(512)
                      curr_addr = curr_addr[0]
                      try:
                          curr_name = socket.gethostbyaddr(curr_addr)[0]
                      except socket.error:
                          curr_name = curr_addr
                  except socket.error:
                      pass
                  finally:
                      send_socket.close()
                      recv_socket.close()
          
                  if curr_addr is not None:
                      curr_host = "%s (%s)" % (curr_name, curr_addr)
                  else:
                      curr_host = "*"
                  print "%d\t%s" % (ttl, curr_host)
          
                  ttl += 1
                  if curr_addr == dest_addr or ttl >= max_hops:
                      break
          
          if __name__ == "__main__":
              main('google.com')
          
          
          1 Reply Last reply Reply Quote 0
          • hallaste
            hallaste last edited by

            Output I get with Python 2.7.5 is:

            1	10.11.0.254 (10.11.0.254)
            2	10.5.1.1 (10.5.1.1)
            3	173-161-242-118-Philadelphia.hfc.comcastbusiness.net (173.161.242.118)
            4	50.166.146.1 (50.166.146.1)
            5	68.86.221.37 (68.86.221.37)
            6	WGS_IT (10.5.8.83)
            7	he-3-5-0-0-11-cr01.ashburn.va.ibone.comcast.net (68.86.92.161)
            8	be-24-pe06.ashburn.va.ibone.comcast.net (68.86.82.162)
            
            1 Reply Last reply Reply Quote 0
            • filippocld223
              filippocld223 last edited by

              good :-)

              1 Reply Last reply Reply Quote 0
              • filippocld223
                filippocld223 last edited by

                it gives an error in line 11: operation not permitted

                1 Reply Last reply Reply Quote 0
                • hallaste
                  hallaste last edited by

                  Yes, I have tried everything I can think of to get he the code running in Pythonista, but with no luck. I was hoping that you could point me in a direction to solve the problem, as the code works in Python 2.7.5

                  1 Reply Last reply Reply Quote 0
                  • hallaste
                    hallaste last edited by

                    will try Pipista, thanks.

                    1 Reply Last reply Reply Quote 0
                    • filippocld223
                      filippocld223 last edited by

                      it's for apple sandboxing

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors