{"id":336,"date":"2008-07-27T23:49:44","date_gmt":"2008-07-28T03:49:44","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/zeroday\/2008\/07\/27\/wishlist-scapy-traceroute-object-pickling\/"},"modified":"2008-07-27T23:49:44","modified_gmt":"2008-07-28T03:49:44","slug":"wishlist-scapy-traceroute-object-pickling","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/zeroday\/2008\/07\/27\/wishlist-scapy-traceroute-object-pickling\/","title":{"rendered":"Wishlist: Scapy traceroute object pickling"},"content":{"rendered":"<p>Some of the projects I am working on require that I gather data about particular addresses on the Internet.  One method I&#8217;ve been experimenting with is scapy&#8217;s traceroute function which allows for neat <a href=\"http:\/\/www.secdev.org\/projects\/scapy\/doc\/img\/graph_traceroute.gif\">graphing<\/a> [secdev.org].  One can also combine two arbitrary traceroutes for graphing as simply as:<\/p>\n<p><code><br \/>\ntraceroute1, unans = traceroute([1.2.3.4])<br \/>\ntraceroute2, unans = traceroute([5.6.7.8])<br \/>\ncombined_traceroutes = traceroute1 + traceroute2<br \/>\n<\/code><\/p>\n<p>So for me the next logical step was to start storing all the traceroutes in a database so I could combine two or more at will and see interesting things.  Not only could I see differences in different paths but I could even see changes of a single path over time!  I fought with scapy for a while and finally realized that the export_object and save_object functions are wrappers for cPickle.  I&#8217;m not entirely familiar with Pickle so I&#8217;ve had to do some reading on the topic.  So far it does not look promising.  No one has come up with a solution for this just yet although there are some promising recipes in the O&#8217;Reilly &#8220;Python Cookbook&#8221; which touch on this subject in a more abstract way.  [&#8220;Using the cPickle Module on classes and Instances&#8221;]<\/p>\n<p>I&#8217;ll document some of the errors in case someone else decides to try this and wants to save some time:<\/p>\n<p><code><\/p>\n<p>&gt;&gt;&gt; trace, unans = traceroute([\"4.2.2.2\"])<\/p>\n<p>&gt;&gt;&gt; save_object(\"\/tmp\/hi\", trace)<br \/>\nTraceback (most recent call last):<br \/>\n  File \"\", line 1, in<br \/>\n  File \"scapy.py\", line 876, in save_object<br \/>\n    cPickle.dump(obj,gzip.open(fname,\"wb\"))<br \/>\n  File \"\/usr\/lib\/python2.5\/copy_reg.py\", line 69, in _reduce_ex<br \/>\n    raise TypeError, \"can't pickle %s objects\" % base.__name__<br \/>\nTypeError: can't pickle function objects<\/p>\n<p>&gt;&gt;&gt; export_object(trace)<br \/>\nTraceback (most recent call last):<br \/>\n  File \"\", line 1, in<br \/>\n  File \"scapy.py\", line 867, in export_object<br \/>\n    print base64.encodestring(gzip.zlib.compress(cPickle.dumps(obj,2),9))<br \/>\nPicklingError: Can't pickle : attribute lookup __builtin__.function failed<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some of the projects I am working on require that I gather data about particular addresses on the Internet. One method I&#8217;ve been experimenting with is scapy&#8217;s traceroute function which allows for neat graphing [secdev.org]. One can also combine two arbitrary traceroutes for graphing as simply as: traceroute1, unans = traceroute([1.2.3.4]) traceroute2, unans = traceroute([5.6.7.8]) [&hellip;]<\/p>\n","protected":false},"author":214,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","category-non-sequiter"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/users\/214"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/comments?post=336"}],"version-history":[{"count":0,"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/posts\/336\/revisions"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/media?parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/categories?post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/zeroday\/wp-json\/wp\/v2\/tags?post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}