pax_global_header00006660000000000000000000000064140536547270014527gustar00rootroot0000000000000052 comment=b0204b4d6b6639b711840b1aadb7e82c4ad4b517 ripe-atlas-sagan-1.3.1/000077500000000000000000000000001405365472700146615ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/.gitignore000066400000000000000000000010671405365472700166550ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ bin/ build/ develop-eggs/ dist/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg .eggs # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .cache nosetests.xml coverage.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject # Rope .ropeproject # Django stuff: *.log *.pot # Sphinx documentation docs/_build/ # PyCharm .idea ripe-atlas-sagan-1.3.1/.travis.yml000066400000000000000000000002461405365472700167740ustar00rootroot00000000000000language: python python: - "2.7" - "3.5" - "3.6" - "3.7" install: - pip install . - pip install nose script: - python setup.py test sudo: false ripe-atlas-sagan-1.3.1/CHANGES.rst000066400000000000000000000200311405365472700164570ustar00rootroot00000000000000Changelog ========= * 1.3.1 * Ping edge case fix * Add py37 testing * 1.3.0 * abuf.py: error handling for NS records, extended rcode, cookies and client subnets * 1.2.2 * Catch problems parsing SSL certificates * 1.2.1 * Add support for non-DNS names in subjectAltName extensions * 1.2 * Replaced pyOpenSSL with cryptography * Added parsing of subjectAltName X509 extension * 1.1.11 * Added first version of WiFi results * 1.1.10 * Added a `parse_all_hops` kwarg to the Traceroute class to tell Sagan to stop parsing Hops and Packets once we have all of the last hop statistics (default=True) * Remove dependency on IPy: we were using it for IPv6 canonicalization, but all IPv6 addresses in results should be in canonical form to start with. * 1.1.9 * Removed the `parse_abuf` script because no one was using it and its Python3 support was suspect anyway. * 1.1.8 * Handle case where a traceroute result might not have ``dst_addr`` field. * 1.1.7 * Change condition of traceroute's ``last_hop_responded`` flag. * Add couple of more traceroute's properties. ``is_success`` and ``last_hop_errors``. * Add tests to the package itself. * 1.1.6 * Fix for `Issue #56`_ a case where the ``qbuf`` value wasn't being properly captured. * Fixed small bug that didn't accurately capture the ``DO`` property from the qbuf. * 1.1.5 * We now ignore so-called "late" packets in traceroute results. This will likely be amended later as future probe firmwares are expected to make better use of this value, but until then, Sagan will treat these packets as invalid. * 1.1.4 * Added a ``type`` attribute to all ``Result`` subclasses * Added support for a lot of new DNS answer types, including ``NSEC``, ``PTR``, ``SRV``, and more. These answers do not yet have a complete string representation however. * 1.1.3 * Changed the name of ``TracerouteResult.rtt_median`` to ``TracerouteResult.last_rtt_median``. * Modified the ``DnsResult`` class to allow the "bubbling up" of error statuses. * 1.1.2 * We skipped this number for some reason :-/ * 1.1.1 * Fixed a `string representation bug`_ found by `iortiz`_ * 1.1.0 * **Breaking Change**: the ``Authority`` and ``Additional`` classes were removed, replaced with the appropriate answer types. For the most part, this change should be invisible, as the common properties are the same, but if you were testing code against these class types, you should consider this a breaking change. * **Breaking Change**: The ``__str__`` format for DNS ``RrsigAnswer`` to conform the output of a typical ``dig`` binary. * Added ``__str__`` definitions to DNS answer classes for use with the toolkit. * In an effort to make Sagan (along with Cousteau and the toolkit) more portable, we dropped the requirement for the ``arrow`` package. * 1.0.0 * 1.0! w00t! * **Breaking Change**: the ``data`` property of the ``TxtAnswer`` class was changed from a string to a list of strings. This is a correction from our own past deviation from the RFC, so we thought it best to conform as part of the move to 1.0.0 * Fixed a bug where non-ascii characters in DNS TXT answers resulted in an exception. * 0.8.2 * Fixed a bug related to non-ascii characters in SSL certificate data. * Added a wrapper for json loaders to handle differences between ujson and the default json module. * 0.8.1 * Minor fix to make all ``Result`` objects properly JSON serialisable. * 0.8.0 * Added `iortiz`_'s patch for flags and ``flags`` and ``sections`` properties on DNS ``Answer`` objects. * 0.7.1 * Changed ``README.md`` to ``README.rst`` to play nice with pypi. * 0.7 * Added `pierky`_'s new ``RRSigAnswer`` class to the dns parser. * 0.6.3 * Fixed a bug in how Sagan deals with inappropriate firmware versions * 0.6.2 * Added `pierky`_'s fix to fix AD and CD flags parsing in DNS Header * 0.6.1 * Added ``rtt_min``, ``rtt_max``, ``offset_min``, and ``offset_max`` to ``NTPResult`` * 0.6.0 * Support for NTP measurements * Fixes for how we calculate median values * Smarter setup.py * 0.5.0 * Complete Python3 support! * 0.4.0 * Added better Python3 support. Tests all pass now for ping, traceroute, ssl, and http measurements. * Modified traceroute results to make use of ``destination_ip_responded`` and ``last_hop_responded``, deprecating ``target_responded``. See the docs for details. * 0.3.0 * Added support for making use of some of the pre-calculated values in DNS measurements so you don't have to parse the abuf if you don't need it. * Fixed a bug in the abuf parser where a variable was being referenced by never defined. * Cleaned up some of the abuf parser to better conform to pep8. * 0.2.8 * Fixed a bug where DNS ``TXT`` results with class ``IN`` were missing a ``.data`` value. * Fixed a problem in the SSL unit tests where ``\n`` was being misinterpreted. * 0.2.7 * Made abuf more robust in dealing with truncation. * 0.2.6 * Replaced ``SslResult.get_checksum_chain()`` with the ``SslResult.checksum_chain`` property. * Added support for catching results with an ``err`` property as an actual error. * 0.2.5 * Fixed a bug in how the ``on_error`` and ``on_malformation`` preferences weren't being passed down into the subcomponents of the results. * 0.2.4 * Support for ``seconds_since_sync`` across all measurement types * 0.2.3 * "Treat a missing Type value in a DNS result as a malformation" (Issue #36) * 0.2.2 * Minor bugfixes * 0.2.1 * Added a ``median_rtt`` value to traceroute ``Hop`` objects. * Smarter and more consistent error handling in traceroute and HTTP results. * Added an ``error_message`` property to all objects that is set to ``None`` by default. * 0.2.0 * Totally reworked error and malformation handling. We now differentiate between a result (or portion thereof) being malformed (and therefore unparsable) and simply containing an error such as a timeout. Look for an ``is_error`` property or an ``is_malformed`` property on every object to check for it, or simply pass ``on_malformation=Result.ACTION_FAIL`` if you'd prefer things to explode with an exception. See the documentation for more details * Added lazy-loading features for parsing abuf and qbuf values out of DNS results. * Removed the deprecated properties from ``dns.Response``. You must now access values like ``edns0`` from ``dns.Response.abuf.edns0``. * More edge cases have been found and accommodated. * 0.1.15 * Added a bunch of abuf parsing features from `b4ldr`_ with some help from `phicoh`_. * 0.1.14 * Fixed the deprecation warnings in ``DnsResult`` to point to the right place. * 0.1.13 * Better handling of ``DNSResult`` errors * Rearranged the way abufs were handled in the ``DnsResult`` class to make way for ``qbuf`` values as well. The old method of accessing ``header``, ``answers``, ``questions``, etc is still available via ``Response``, but this will go away when we move to 0.2. Deprecation warnings are in place. * 0.1.12 * Smarter code for checking whether the target was reached in ``TracerouteResults``. * We now handle the ``destination_option_size`` and ``hop_by_hop_option_size`` values in ``TracerouteResult``. * Extended support for ICMP header info in traceroute ``Hop`` class by introducing a new ``IcmpHeader`` class. * 0.1.8 * Broader support for SSL checksums. We now make use of ``md5`` and ``sha1``, as well as the original ``sha256``. .. _Issue #56: https://github.com/RIPE-NCC/ripe.atlas.sagan/issues/56 .. _string representation bug: https://github.com/RIPE-NCC/ripe-atlas-tools/issues/1 .. _b4ldr: https://github.com/b4ldr .. _phicoh: https://github.com/phicoh .. _iortiz: https://github.com/iortiz .. _pierky: https://github.com/pierky ripe-atlas-sagan-1.3.1/CONTRIBUTING.rst000066400000000000000000000047231405365472700173300ustar00rootroot00000000000000How To Contribute ================= We would love to have contributions from everyone and no contribution is too small. Please submit as many fixes for typos and grammar bloopers as you can! To make participation in this project as pleasant as possible for everyone, we adhere to the `Code of Conduct`_ by the Python Software Foundation. The following steps will help you get started: Fork, then clone the repo: .. code:: bash $ git clone git@github.com:your-username/ripe.atlas.sagan.git Make sure the tests pass beforehand: .. code:: bash $ tox or .. code:: bash $ nosetests tests/ Make your changes. Include tests for your change. Make the tests pass: .. code:: bash $ tox or .. code:: bash $ nosetests tests/ Push to your fork and `submit a pull request`_. Here are a few guidelines that will increase the chances of a quick merge of your pull request: - *Always* try to add tests and docs for your code. If a feature is tested and documented, it's easier for us to merge it. - Follow `PEP 8`_. - Write `good commit messages`_. - If you change something that is noteworthy, don't forget to add an entry to the `changes`_. .. note:: - If you think you have a great contribution but aren’t sure whether it adheres -- or even can adhere -- to the rules: **please submit a pull request anyway**! In the best case, we can transform it into something usable, in the worst case the pull request gets politely closed. There’s absolutely nothing to fear. - If you have a great idea but you don't know how or don't have the time to implement it, please consider opening an issue and someone will pick it up as soon as possible. Thank you for considering a contribution to this project! If you have any questions or concerns, feel free to reach out the RIPE Atlas team via the `mailing list`_, `GitHub Issue Queue`_, or `messenger pigeon`_ -- if you must. .. _submit a pull request: https://github.com/RIPE-NCC/ripe.atlas.sagan/compare/ .. _PEP 8: https://www.python.org/dev/peps/pep-0008/ .. _good commit messages: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html .. _Code of Conduct: https://www.python.org/psf/codeofconduct/ .. _changes: https://github.com/RIPE-NCC/ripe.atlas.sagan/blob/master/CHANGES.rst .. _mailing list: https://www.ripe.net/mailman/listinfo/ripe-atlas .. _GitHub Issue Queue: https://github.com/RIPE-NCC/ripe.atlas.sagan/issues .. _messenger pigeon: https://tools.ietf.org/html/rfc1149 ripe-atlas-sagan-1.3.1/LICENSE000066400000000000000000001044601405365472700156730ustar00rootroot00000000000000GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {one line to give the program's name and a brief idea of what it does.} Copyright (C) {year} {name of author} This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: {project} Copyright (C) {year} {fullname} This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .ripe-atlas-sagan-1.3.1/MANIFEST.in000066400000000000000000000002041405365472700164130ustar00rootroot00000000000000include CHANGES.rst include LICENSE include README.rst include MANIFEST.in recursive-include ripe *.py recursive-include tests *.py ripe-atlas-sagan-1.3.1/README.rst000066400000000000000000000206511405365472700163540ustar00rootroot00000000000000RIPE Atlas Sagan |Build Status| |Documentation| =============================================== A parsing library for RIPE Atlas measurement results Why this exists --------------- RIPE Atlas generates a **lot** of data, and the format of that data changes over time. Often you want to do something simple like fetch the median RTT for each measurement result between date ``X`` and date ``Y``. Unfortunately, there are dozens of edge cases to account for while parsing the JSON, like the format of errors and firmware upgrades that changed the format entirely. To make this easier for our users (and for ourselves), we wrote an easy to use parser that's smart enough to figure out the best course of action for each result, and return to you a useful, native Python object. How to install -------------- The stable version should always be in PyPi, so you can install it with ``pip``: .. code:: bash $ pip install ripe.atlas.sagan Better yet, make sure you get ujson and sphinx installed with it: .. code:: bash $ pip install ripe.atlas.sagan[fast,doc] Troubleshooting ~~~~~~~~~~~~~~~ Some setups (like MacOS) have trouble with building the dependencies required for reading SSL certificates. If you don't care about SSL stuff and only want to use sagan to say, parse traceroute or DNS results, then you can do the following: .. code:: bash $ SAGAN_WITHOUT_SSL=1 pip install ripe.atlas.sagan Quickstart: How To Use It ------------------------- You can parse a result in a few ways. You can just pass the JSON-encoded string: .. code:: python from ripe.atlas.sagan import PingResult my_result = PingResult("") print(my_result.rtt_median) 123.456 print(my_result.af) 6 You can do the JSON-decoding yourself: .. code:: python from ripe.atlas.sagan import PingResult my_result = PingResult( json.loads("") ) print(my_result.rtt_median) 123.456 print(my_result.af) 6 You can let the parser guess the right type for you, though this incurs a small performance penalty: .. code:: python from ripe.atlas.sagan import Result my_result = Result.get("") print(my_result.rtt_median) 123.456 print(my_result.af) 6 What it supports ---------------- Essentially, we tried to support everything. If you pass in a DNS result string, the parser will return a ``DNSResult`` object, which contains a list of ``Response``'s, each with an ``abuf`` property, as well as all of the information in that abuf: header, question, answer, etc. .. code:: python from ripe.atlas.sagan import DnsResult my_dns_result = DnsResult("") my_dns_result.responses[0].abuf # The entire string my_dns_result.responses[0].abuf.header.arcount # Decoded from the abuf We do the same sort of thing for SSL measurements, traceroutes, everything. We try to save you the effort of sorting through whatever is in the result. Which attributes are supported? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Every result type has its own properties, with a few common between all types. Specifically, these attributes exist on all ``*Result`` objects: - ``created`` An datetime object of the ``timestamp`` field - ``measurement_id`` - ``probe_id`` - ``firmware`` An integer representing the firmware version - ``origin`` The ``from`` attribute in the result - ``is_error`` Set to ``True`` if an error was found Additionally, each of the result types have their own properties, like ``packet_size``, ``responses``, ``certificates``, etc. You can take a look at the classes themselves, or just look at the tests if you're curious. But to get you started, here are some examples: .. code:: python # Ping ping_result.packets_sent # Int ping_result.rtt_median # Float, rounded to 3 decimal places ping_result.rtt_average # Float, rounded to 3 decimal places # Traceroute traceroute_result.af # 4 or 6 traceroute_result.total_hops # Int traceroute_result.destination_address # An IP address string # DNS dns_result.responses # A list of Response objects dns_result.responses[0].response_time # Float, rounded to 3 decimal places dns_result.responses[0].headers # A list of Header objects dns_result.responses[0].headers[0].nscount # The NSCOUNT value for the first header dns_result.responses[0].questions # A list of Question objects dns_result.responses[0].questions[0].type # The TYPE value for the first question dns_result.responses[0].abuf # The raw, unparsed abuf string # SSL Certificates ssl_result.af # 4 or 6 ssl_result.certificates # A list of Certificate objects ssl_result.certificates[0].checksum # The checksum for the first certificate # HTTP http_result.af # 4 or 6 http_result.uri # A URL string http_result.responses # A list of Response objects http_result.responses[0].body_size # The size of the body of the first response # NTP ntp_result.af # 4 or 6 ntp_result.stratum # Statum id ntp_result.version # Version number ntp_result.packets[0].final_timestamp # A float representing a high-precision NTP timestamp ntp_result.rtt_median # Median value for packets sent & received What it requires ---------------- As you might have guessed, with all of this magic going on under the hood, there are a few dependencies: - `cryptography`_ (Optional: see "Troubleshooting" above) - `python-dateutil`_ - `pytz`_ - `IPy`_ Additionally, we recommend that you also install `ujson`_ as it will speed up the JSON-decoding step considerably, and `sphinx`_ if you intend to build the documentation files for offline use. Running Tests ------------- There's a full battery of tests for all measurement types, so if you've made changes and would like to submit a pull request, please run them (and update them!) before sending your request: .. code:: bash $ python setup.py test You can also install ``tox`` to test everything in all of the supported Python versions: .. code:: bash $ pip install tox $ tox Further Documentation --------------------- Complete documentation can always be found on `Read the Docs`_, and if you're not online, the project itself contains a ``docs`` directory -- everything you should need is in there. Who's Responsible for This? --------------------------- Sagan is actively maintained by the RIPE NCC and primarily developed by `Daniel Quinn`_, while the abuf parser is mostly the responsibility of `Philip Homburg`_ with an assist from Bert Wijnen and Rene Wilhelm who contributed to the original script. `Andreas Stirkos`_ did the bulk of the work on NTP measurements and fixed a few bugs, and big thanks go to `Chris Amin`_, `John Bond`_, and `Pier Carlo Chiodi`_ for finding and fixing stuff where they've run into problems. Colophon -------- But why "`Sagan`_"? The RIPE Atlas team decided to name all of its modules after explorers, and what better name for a parser than that of the man who spent decades reaching out to the public about the wonders of the cosmos? .. _python-dateutil: https://pypi.python.org/pypi/python-dateutil .. _cryptography: https://pypi.python.org/pypi/cryptography .. _pytz: https://pypi.python.org/pypi/pytz .. _IPy: https://pypi.python.org/pypi/IPy/ .. _ujson: https://pypi.python.org/pypi/ujson .. _sphinx: https://pypi.python.org/pypi/Sphinx .. _Read the Docs: http://ripe-atlas-sagan.readthedocs.org/en/latest/ .. _Daniel Quinn: https://github.com/danielquinn .. _Philip Homburg: https://github.com/philiphomburg .. _Andreas Stirkos: https://github.com/astrikos .. _Chris Amin: https://github.com/chrisamin .. _John Bond: https://github.com/b4ldr .. _Pier Carlo Chiodi: https://github.com/pierky .. _Sagan: https://en.wikipedia.org/wiki/Carl_Sagan .. |Build Status| image:: https://travis-ci.org/RIPE-NCC/ripe.atlas.sagan.png?branch=master :target: https://travis-ci.org/RIPE-NCC/ripe.atlas.sagan .. |Documentation| image:: https://readthedocs.org/projects/ripe-atlas-sagan/badge/?version=latest :target: http://ripe-atlas-sagan.readthedocs.org/en/latest/?badge=latest :alt: Documentation Status ripe-atlas-sagan-1.3.1/docs/000077500000000000000000000000001405365472700156115ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/docs/Makefile000066400000000000000000000152121405365472700172520ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/RIPEAtlasSagan.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/RIPEAtlasSagan.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/RIPEAtlasSagan" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/RIPEAtlasSagan" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." ripe-atlas-sagan-1.3.1/docs/changelog.rst000066400000000000000000000000341405365472700202670ustar00rootroot00000000000000.. include:: ../CHANGES.rst ripe-atlas-sagan-1.3.1/docs/conf.py000066400000000000000000000252161405365472700171160ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # RIPE Atlas Sagan documentation build configuration file, created by # sphinx-quickstart on Tue Apr 29 13:41:57 2014. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os __version__ = None exec(open("../ripe/atlas/sagan/version.py").read()) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.viewcode', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'RIPE Atlas Sagan' copyright = u'2014, RIPE NCC' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # If the build process ever explodes here, it's because you've set the version # number in ripe.atlas.tools.version to a string in a format other than x.y.z # # The short X.Y version. version = ".".join(__version__.split(".")[:2]) # The full version, including alpha/beta/rc tags. release = ".".join(__version__.split(".")[:3]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'RIPEAtlasSagandoc' # # Attempt to use the ReadTheDocs theme. If it's not installed, fallback to # the default. # try: import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] except ImportError: pass # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'RIPEAtlasSagan.tex', u'RIPE Atlas Sagan Documentation', u'Daniel Quinn', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'ripeatlassagan', u'RIPE Atlas Sagan Documentation', [u'Daniel Quinn'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'RIPEAtlasSagan', u'RIPE Atlas Sagan Documentation', u'Daniel Quinn', 'RIPEAtlasSagan', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False # -- Options for Epub output ---------------------------------------------- # Bibliographic Dublin Core info. epub_title = u'RIPE Atlas Sagan' epub_author = u'Daniel Quinn' epub_publisher = u'Daniel Quinn' epub_copyright = u'2014, Daniel Quinn' # The basename for the epub file. It defaults to the project name. #epub_basename = u'RIPE Atlas Sagan' # The HTML theme for the epub output. Since the default themes are not optimized # for small screen space, using the same theme for HTML and epub output is # usually not wise. This defaults to 'epub', a theme designed to save visual # space. #epub_theme = 'epub' # The language of the text. It defaults to the language option # or en if the language is not set. #epub_language = '' # The scheme of the identifier. Typical schemes are ISBN or URL. #epub_scheme = '' # The unique identifier of the text. This can be a ISBN number # or the project homepage. #epub_identifier = '' # A unique identification for the text. #epub_uid = '' # A tuple containing the cover image and cover page html template filenames. #epub_cover = () # A sequence of (type, uri, title) tuples for the guide element of content.opf. #epub_guide = () # HTML files that should be inserted before the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_pre_files = [] # HTML files shat should be inserted after the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_post_files = [] # A list of files that should not be packed into the epub file. epub_exclude_files = ['search.html'] # The depth of the table of contents in toc.ncx. #epub_tocdepth = 3 # Allow duplicate toc entries. #epub_tocdup = True # Choose between 'default' and 'includehidden'. #epub_tocscope = 'default' # Fix unsupported image types using the PIL. #epub_fix_images = False # Scale large images. #epub_max_image_width = 0 # How to display URL addresses: 'footnote', 'no', or 'inline'. #epub_show_urls = 'inline' # If false, no index is generated. #epub_use_index = True ripe-atlas-sagan-1.3.1/docs/contributing.rst000066400000000000000000000000411405365472700210450ustar00rootroot00000000000000.. include:: ../CONTRIBUTING.rst ripe-atlas-sagan-1.3.1/docs/index.rst000066400000000000000000000021551405365472700174550ustar00rootroot00000000000000.. RIPE Atlas Sagan documentation master file, created by sphinx-quickstart on Tue Apr 29 13:41:57 2014. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to RIPE Atlas Sagan's documentation! ******************************************** A parsing library for RIPE Atlas measurement results .. _index-why-this-exists: Why This Exists =============== RIPE Atlas generates a **lot** of data, and the format of that data changes over time. Often you want to do something simple like fetch the median RTT for each measurement result between date `X` and date `Y`. Unfortunately, there are are dozens of edge cases to account for while parsing the JSON, like the format of errors and firmware upgrades that changed the format entirely. To make this easier for our users (and for ourselves), we wrote an easy to use parser that's smart enough to figure out the best course of action for each result, and return to you a useful, native Python object. Contents: .. toctree:: :maxdepth: 2 installation use types contributing changelog ripe-atlas-sagan-1.3.1/docs/installation.rst000066400000000000000000000051101405365472700210410ustar00rootroot00000000000000.. _requirements-and-installation: Requirements & Installation *************************** .. _installation-requirements: Requirements ============ As you might have guessed, with all of the magic going on under the hood, there are a few dependencies: * `cryptography`_ * `python-dateutil`_ * `pytz`_ Additionally, we recommend that you also install `ujson`_ as it will speed up the JSON-decoding step considerably, and `sphinx`_ if you intend to build the documentation files for offline use. .. _cryptography: https://pypi.python.org/pypi/cryptography .. _python-dateutil: https://pypi.python.org/pypi/python-dateutil/ .. _pytz: https://pypi.python.org/pypi/pytz/ .. _ujson: https://pypi.python.org/pypi/ujson/ .. _sphinx: https://pypi.python.org/pypi/Sphinx/ .. _installation: Installation ============ Installation should be easy, though it may take a while to install all of the aforementioned requirements. Using pip is the recommended method. .. _installation-from-pip: Using pip --------- The quickest and easiest way to install Sagan is to use ``pip``:: $ pip install ripe.atlas.sagan .. _installation-from-github: From GitHub ----------- If you're feeling a little more daring and want to use whatever is on GitHub, you can have pip install right from there:: $ pip install git+https://github.com/RIPE-NCC/ripe.atlas.sagan.git .. _installation-from-tarball: From a Tarball -------------- If for some reason you want to just download the source and install it manually, you can always do that too. Simply un-tar the file and run the following in the same directory as ``setup.py``.:: $ python setup.py install .. _installation-troubleshooting: Troubleshooting --------------- Some setups (like MacOS) have trouble with building the dependencies required for reading SSL certificates. If you don't care about SSL stuff and only want to use sagan to say, parse traceroute or DNS results, then you can do the following: $ SAGAN_WITHOUT_SSL=1 pip install ripe.atlas.sagan More information can also be found `here`_. If you *do* care about SSL and have to use a Mac, then `this issue`_ will likely be of assistance. Essentially, you will need to uninstall Xcode (if it's installed already), then attempt to use ``gcc``. This will trigger the OS to ask if you want to install the Xcode compilation tools. Click ``install``, and when that's finished, install Sagan with this command: $ CFLAGS="-I/usr/include" pip install ripe.atlas.sagan .. _here: https://cryptography.io/en/latest/installation/ .. _this issue: https://github.com/RIPE-NCC/ripe.atlas.sagan/issues/52 ripe-atlas-sagan-1.3.1/docs/make.bat000066400000000000000000000150751405365472700172260ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. xml to make Docutils-native XML files echo. pseudoxml to make pseudoxml-XML files for display purposes echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) %SPHINXBUILD% 2> nul if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\RIPEAtlasSagan.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\RIPEAtlasSagan.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdf" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf cd %BUILDDIR%/.. echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdfja" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf-ja cd %BUILDDIR%/.. echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) if "%1" == "xml" ( %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml if errorlevel 1 exit /b 1 echo. echo.Build finished. The XML files are in %BUILDDIR%/xml. goto end ) if "%1" == "pseudoxml" ( %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml if errorlevel 1 exit /b 1 echo. echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. goto end ) :end ripe-atlas-sagan-1.3.1/docs/types.rst000066400000000000000000001010051405365472700175040ustar00rootroot00000000000000.. _attributes-methods: Attributes & Methods ******************** .. _common-attributes: Common Attributes ================= All measurement results have a few common properties. ===================== ======== ================================================================ Property Type Explanation ===================== ======== ================================================================ raw_data dict The entire measurement result, as-is from `json.loads()` created datetime The time at which this result was initiated created_timestamp int A Unix timestamp value for the ``created`` attribute measurement_id int probe_id int firmware int The probe firmware release origin str The IP address of the probe seconds_since_sync int The number of seconds since the probe last syncronised its clock is_malformed bool Whether the result (or related portion thereof) is unparseable is_error bool Whether or not there were errors in parsing/handling this result error_message str If the result is an error, the message string is in here ===================== ======== ================================================================ .. _ping: Ping ==== The simplest measurement type, ``ping`` measurement results contain all of the properties :ref:`common to all measurements ` as well as the following: ===================== ===== =================================================================================== Property Type Explanation ===================== ===== =================================================================================== af int The address family. It's always either a ``4`` or a ``6``. duplicates int The number duplicates found rtt_average float rtt_median float rtt_min float rtt_max float packets_sent int packets_received int packet_size int destination_name str The string initially given as the target. It can be an IP address or a domain name destination_address str An IP address represented as a string step int The number of seconds between ping requests (interval) packets list A list of ping :ref:`ping-packet` objects ===================== ===== =================================================================================== .. _ping-packet: Packet ------ Each ping request sends ``n`` packets, where ``n`` is a value specified at measurement creation time. We represent these packets as ``Packet`` objects. ===================== ===== ================================================================ Property Type Explanation ===================== ===== ================================================================ rtt float dup bool Set to ``True`` if this packet is a duplicate ttl int source_address str An IP address represented as a string ===================== ===== ================================================================ .. _traceroute: Traceroute ========== Probably the largest result type, ``traceroute`` measurement results contain all of the properties :ref:`common to all measurements ` as well as the following: ======================== ======== =================================================================================== Property Type Explanation ======================== ======== =================================================================================== af int The address family. It's always either a ``4`` or a ``6``. destination_name str The string initially given as the target. It can be an IP address or a domain name destination_address str An IP address represented as a string source_address str An IP address represented as a string end_time datetime The time at which the traceroute finished end_time_timestamp int A Unix timestamp for the ``end_time`` attribute paris_id int size int The packet size protocol str One of ``ICMP``, ``TCP``, ``UDP`` hops list A list of :ref:`traceroute-hop` objects. If the ``parse_all_hops`` parameter is ``False``, this will only contain the last hop. total_hops int The total number of hops ip_path list A list of dicts containing the IPs at each hop. This is just for convenience as all of these values are accessible via the :ref:`traceroute-hop` and :ref:`traceroute-packet` objects. last_median_rtt float The median value of all RTTs from the last successful hop destination_ip_responded bool Set to ``True`` if the last hop was a response from the destination IP last_hop_responded bool Set to ``True`` if the last hop was a response at all is_success bool Set to ``True`` if the traceroute finished successfully last_hop_errors list A list of last hop's errors ======================== ======== =================================================================================== It is also possible to supply the following parameter to control parsing of Traceroute results: ============== ==== ======= =========== Parameter Type Default Explanation ============== ==== ======= =========== parse_all_hops bool True Set to ``False`` to stop parsing ``Hop`` objects after the ``last_*`` properties (see above) have been set. This will cause ``hops`` to only contain the last ``Hop``. ============== ==== ======= =========== .. _traceroute-hop: Hop ---- Each hop in the traceroute is available as a ``Hop`` object. ===================== ===== ================================================================ Property Type Explanation ===================== ===== ================================================================ index int The hop number, starting with 1 packets list A list of tracroute :ref:`traceroute-packet` objects median_rtt float The median value of all RTTs of the hop ===================== ===== ================================================================ .. _traceroute-packet: Packet ------ ======================= ========== =========================================================================================== Property Type Explanation ======================= ========== =========================================================================================== origin str The IP address of where the packet is coming from rtt float size int ttl int arrived_late_by int If the packet arrived late, this number represents "how many hops ago" this packet was sent internal_ttl int The time-to-live for the packet that triggered the error ICMP. The default is 1 destination_option_size int The size of the IPv6 destination option header hop_by_hop_option_size int The size of the IPv6 hop-by-hop option header icmp_header IcmpHeader See :ref:`traceroute-icmp-header` below ======================= ========== =========================================================================================== .. _traceroute-icmp-header: IcmpHeader ---------- This class is slightly different than other parts of Sagan as it in ``objects`` we find a complex generic list containing generic dictionaries pulled directly from the JSON blob. The decision not to further parse this bob into separate Python models was made based on the assumption that much of this section is very edge-case and the contents are present sporadically. If however there is a demand for further development of this portion of the result, we can expand it. Until then though, ``IcmpHeader`` is a very simple class, the majority of data living in ``objects``. For further information about this portion of a traceroute result, you should consult our `data structure documentation`_ .. _data structure documentation: https://atlas.ripe.net/docs/data_struct/#v4610_traceroute ===================== ========== ========================================================================= Property Type Explanation ===================== ========== ========================================================================= version int RFC4884 version rfc4884 bool ``True`` if length indication is present, ``False`` otherwise objects list As mentioned above a complete dump of whatever is in the ``obj`` property ===================== ========== ========================================================================= .. _dns: DNS ==== The most complicated result type, ``dns`` measurement results contain all of the properties :ref:`common to all measurements ` as well as the following: ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== responses list A list of DNS :ref:`dns-response` objects (see below) ===================== ======== =================================================================================== .. _dns-response: Response -------- Most DNS measurement results consist of a single response, but in some cases, there may be more than one. Regardless, every ``Response`` instance has the following properties: ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The fragment of the initial JSON that pertains to this response af int The address family. It's always either a ``4`` or a ``6``. destination_address str An IP address represented as a string source_address str An IP address represented as a string protocol str One of ``TCP``, ``UDP`` abuf Message See :ref:`dns-message` below qbuf Message See :ref:`dns-message` below response_time float Time, in milliseconds until the response was received response_id int The sequence number of this result within a group of results, available if the resolution was done by the probe's local resolver ===================== ======== =================================================================================== .. _dns-message: Message ------- Responses can contain either an ``abuf`` or a ``qbuf`` which are both ``Message`` objects. If you want the string representation, simply cast the object as a string with ``str()``. ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The fragment of the initial JSON that pertains to this response header Header See :ref:`dns-header` below edns0 Edns0 See :ref:`dns-edns0` below, if any questions list A list of :ref:`dns-question` objects answers list A list of :ref:`dns-answer` objects, if any authorities list A list of :ref:`dns-answer` objects, if any additionals list A list of :ref:`dns-answer` objects, if any ===================== ======== =================================================================================== .. _dns-message-precalculatedvalues: A note on pre-calculated values ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ By default, when you pass a result into Sagan, it will attempt to parse the ``abuf`` and ``qbuf`` strings (if any) into ``Message`` objects. However, some of the values in that abuf may have already been pre-calculated and stored alongside the other attributes in the result. Many ``Header`` values for example, can be found in the raw result (outside of the abuf string), so parsing the abuf for these values is redundant and potentially unnecessary if these values are all you need. For this case, Sagan supports passing ``parse_buf=False`` to the ``DnsResult`` class. If you opt for this method, the abuf will not be parsed, and any values not immediately available in the result will return ``None``. For example:: from ripe.atlas.sagan import DnsResult my_result = DnsResult( '', parse_buf=False ) result.responses[0].abuf.answers[0].name # "version.bind" result.responses[0].abuf.answers[0].klass # None result.responses[0].abuf.answers[0].rd_length # None result.responses[0].abuf.answers[0].type # "TXT" result.responses[0].abuf.answers[0].ttl # None result.responses[0].abuf.answers[0].data # "Some RDATA value" Note also that ``Result.get()`` accepts ``parse_buf=`` as well:: from ripe.atlas.sagan import Result my_result = Result.get( '', parse_buf=False ) result.responses[0].abuf.answers[0].name # "version.bind" ... .. _dns-header: Header ~~~~~~ All of these properties conform to `RFC 1035`_, so we won't go into detail about them here. .. _RFC 1035: https://www.ietf.org/rfc/rfc1035.txt ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The portion of the parsed abuf that represents this section aa bool qr bool nscount int Otherwise known as the namserver count or authority count. qdcount int ancount int tc bool rd bool arcount int return_code str opcode str ra bool z int id int ===================== ======== =================================================================================== .. _dns-question: Question ~~~~~~~~ The question section of the response. **NOTE**: In keeping with Python conventions, we use the propertyname ``klass`` here instead of the more intuitive (and illegal in Python) ``class``. It may be confusing for non-Python programmers, but unfortunately it's a limitation of the language. ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The portion of the parsed abuf that represents this section klass str The ``CLASS`` value, spelt this way to conform to Python norms type str name str ===================== ======== =================================================================================== .. _dns-answer: Answer ~~~~~~ The answer section of the response. **NOTE**: In keeping with Python conventions, we use the propertyname ``klass`` here instead of the more intuitive (and illegal in Python) ``class``. It may be confusing for non-Python programmers, but unfortunately it's a limitation of the language. ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The portion of the parsed abuf that represents this section klass str The ``CLASS`` value, spelt this way to conform to Python norms type str name str ttl int address str An IP address rd_length int ===================== ======== =================================================================================== There is a different sub-class of ``Answer`` for every DNS answer type. These are all briefly outlined below. .. _dns-answer-a: AAnswer & AAAAAnswer .................... Both of these classes have only one additional property to their parent ``Answer`` class: ``address``. ===================== ======== ==================== Property Type Explanation ===================== ======== ==================== answer str The address response ===================== ======== ==================== .. _dns-answer-ns: NsAnswer & CnameAnswer ...................... Both of these subclasses only have one additional property: ``target``. ===================== ======== ========================= Property Type Explanation ===================== ======== ========================= target str The address of the target ===================== ======== ========================= .. _dns-answer-mx: MxAnswer ........ ===================== ======== ========================= Property Type Explanation ===================== ======== ========================= preference int The preference number mail_exchanger str The exchanger name ===================== ======== ========================= .. _dns-answer-soa: SoaAnswer ......... There are a lot of additional properties for SOA answers, as well as a few aliases for people who like human-readable names. ===================== ======== ========================= Property Type Explanation ===================== ======== ========================= mname str The master server name rname str The maintainer name serial int refresh int retry int expire int minimum int The negative TTL master_server_name str An alias for ``mname`` maintainer_name str An alias for ``rname`` negative_ttl str An alias for ``minimum`` nxdomain str An alias for ``minimum`` ===================== ======== ========================= .. _dns-answer-ds: DsAnswer ........ ===================== ======== Property Type ===================== ======== tag int algorithm int digest_type int delegation_key str ===================== ======== .. _dns-answer-dnskey: DnskeyAnswer ............ ===================== ======== Property Type ===================== ======== flags int algorithm int protocol int key str ===================== ======== .. _dns-answer-txt: TxtAnswer ......... A class for DNS TXT responses, ``TxtAnswer`` has all of the properties of an ``Answer`` class, but with two additional properties: ===================== ======== ========================================================================================================= Property Type Explanation ===================== ======== ========================================================================================================= data list The response text, represented as a list of strings, though in most cases, the list has only one element. data_string str The string representation of ``data``, joining all elements of the list with a space. ===================== ======== ========================================================================================================= .. _dns-answer-rrsig: RRSigAnswer ........... ===================== ======== Property Type ===================== ======== type_covered str algorithm int labels int original_ttl int signature_expiration int signature_inception int key_tag int signer_name str signature str ===================== ======== Note that ``RRsigAnswer``s have a special string representation, where the values of ``type_covered``, ``algorithm``, ``labels``, ``original_ttl``, ``signature_expiration``, ``signature_inception``, ``key_tag``, ``signer_name`, and ``signature`` are all concatenated with spaces. .. _dns-answer-nsec: NsecAnswer .......... ===================== ======== Property Type ===================== ======== next_domain_name str types list ===================== ======== .. _dns-answer-nsec3: Nsec3Answer ........... ===================== ======== Property Type ===================== ======== hash_algorithm int flags int iterations int salt str hash str types list ===================== ======== .. _dns-answer-nsec3param: Nsec3ParamAnswer ................ ===================== ======== Property Type ===================== ======== algorithm int flags int iterations int salt str ===================== ======== .. _dns-answer-ptr: PtrAnswer ......... ===================== ======== Property Type ===================== ======== target str ===================== ======== .. _dns-answer-srv: SrvAnswer ......... ===================== ======== Property Type ===================== ======== priority int weight int port int target str ===================== ======== .. _dns-answer-sshfp: SshfpAnswer ........... ===================== ======== Property Type ===================== ======== algorithm int digest_type int fingerprint str ===================== ======== .. _dns-answer-tlsa: TlsaAnswer .......... =========================== ======== Property Type =========================== ======== certificate_usage int selector int matching_type int certificate_associated_data str =========================== ======== .. _dns-answer-hinfo: HinfoAnswer ........... ===================== ======== Property Type ===================== ======== cpu str os str ===================== ======== .. _dns-edns0: EDNS0 ~~~~~ The optional EDNS0 section of the response. ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The portion of the parsed abuf that represents this section extended_return_code int name str type str udp_size int version int z int options list A list of :ref:`dns-edns0-option` objects ===================== ======== =================================================================================== .. _dns-edns0-option: Option ...... ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The portion of the EDNS0 section that represents this option nsid str code int length int name str ===================== ======== =================================================================================== .. _sslcert: SSL Certificate =============== SSL certificate measurement results contain all of the properties :ref:`common to all measurements ` as well as the following: ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== af int The address family. It's always either a ``4`` or a ``6``. destination_name str The string initially given as the target. It can be an IP address or a domain name destination_address str An IP address source_address str An IP address port int The port numer method str This should always be "SSL" version str response_time float Time, in milliseconds until the response was received time_to_connect float Time, in milliseconds until the connection was established certificates list A list of :ref:`sslcert-certificate` objects is_signed bool Set to ``True`` if the certificate is self-signed checksum_chain str A list of all checksums for all certificates in this result, joined with the arbitrary string ``::``. This can come in handy when you're trying to compare checksums of multiple results. ===================== ======== =================================================================================== .. _sslcert-certificate: Certificate ----------- Each SSL certificate measurement result can contain multiple ``Certificate`` objects. ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The fragment of the initial JSON that pertains to this response subject_cn str The subject's common name subject_o str The subject's organisation subject_c str The subject's country issuer_cn str The issuer's common name issuer_o str The issuer's organisation issuer_c str The issuer's country valid_from datetime valid_until datetime checksum_md5 str The md5 checksum checksum_sha1 str The sha1 checksum checksum_sha256 str The sha256 checksum has_expired bool Set to ``True`` if the certificate is no longer valid extensions dict Parsed extensions. For now it can only be subjectAltName, which is a list of names contained in the SAN extension, if that exists. ===================== ======== =================================================================================== .. _http: HTTP ==== HTTP measurement results contain all of the properties :ref:`common to all measurements ` as well as the following: ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== uri str method str The HTTP method responses list A list of :ref:`http-response` objects ===================== ======== =================================================================================== .. _http-response: Response -------- Each HTTP measurement result can contain multiple ``Response`` objects. ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== raw_data dict The portion of the JSON that pertains to this response af int The address family. It's always either a ``4`` or a ``6``. body_size int The total number of bytes in the body head_size int The total number of bytes in the head destination_address str An IP address source_address str An IP address code int The HTTP response code response_time float Time, in milliseconds until the response was received version str The HTTP version ===================== ======== =================================================================================== .. _ntp: NTP ==== NTP measurement results contain all of the properties :ref:`common to all measurements ` as well as the following: ===================== ======== =================================================================================== Property Type Explanation ===================== ======== =================================================================================== leap_second_indicator str Leap second indicator poll int Poll interval precision float protocol str ``UDP`` reference_id str Reference id returned by server reference_time float The NTP time the server last contacted the reference time source root_delay float Round trip time from the server to the reference time source root_dispersion float Accuracy of server's clock stratum int How far in hops is server from reference time source version int The NTP version mode str Ntp communication mode. Usually ``server`` rtt_median float The median value of packets' rtt offset_median float The median value of the packets' offset packets list A list of ntp :ref:`ntp-packet` objects ===================== ======== =================================================================================== .. _ntp-packet: Response -------- Each HTTP measurement result can contain multiple ``Response`` objects. ======================== ======== =================================================================================== Property Type Explanation ======================== ======== =================================================================================== raw_data dict The portion of the JSON that pertains to this response offset float The NTP offset rtt float The response time final_timestamp float A full-precision Unix timestamp for when the NTP client received the response origin_timestamp float A full-precision Unix timestamp for when the NTP client send packet to the server received_timestamp float A full-precision Unix timestamp for when the NTP server received the request transmitted_timestamp float A full-precision Unix timestamp for when the NTP server transmitted the response final_time datetime A Python datetime object with limited precision[1] based on ``final_timestamp`` origin_time datetime A Python datetime object with limited precision[1] based on ``origin_timestamp`` received_time datetime A Python datetime object with limited precision[1] based on ``received_timestamp`` transmitted_time datetime A Python datetime object with limited precision[1] based on ``transmitted_timestamp`` ======================== ======== =================================================================================== .. [1] Python ``datetime`` objects are limited to 6 decimal places of precision. ripe-atlas-sagan-1.3.1/docs/use.rst000066400000000000000000000223151405365472700171420ustar00rootroot00000000000000.. _use-and-examples: Use & Examples ************** The library contains a full test suite for each measurement type, so if you're looking for examples, it's a good idea to start there. For this document we'll cover basic usage and some simple examples to get you started. .. _use: How To Use This Library ======================= Sagan's sole purpose is to make RIPE Atlas measurements manageable from within Python. You shouldn't have to be fiddling with JSON, or trying to find values that changed locations between firmware versions. Instead, you should always be able to pass in the JSON string and immediately get usable Python objects. .. _use-basics: Important Note -------------- The one thing that tends to confuse people when first trying out Sagan is that this library operates on **single measurement results**, and not a list of results. If you have a list of results (for example, the output of the measurement results API), then you must loop over those results and pass each result to Sagan for parsing. Basics ------ To that end, the interface is pretty simple. If you have a ping measurement result, then use the PingResult class to make use of the data:: from ripe.atlas.sagan import PingResult my_result = PingResult('this is where your big JSON blob goes') my_result.af # Returns 6 my_result.rtt_median # Returns 123.456 Note that ``rtt_median`` isn't actually in the JSON data passed in. It's calculated during the parsing phase so you don't need to fiddle with looping over attributes in a list and doing the math yourself. .. _use-plain-text-not-required: Plain Text Not Required ----------------------- It should be noted that while all of the examples here use a plain text string for our results, Sagan doesn't force you to pass in a string. It's just as happy with a Python dict, the result of already running your result string through ``json.loads()``:: import json from ripe.atlas.sagan import PingResult my_result_dict = json.loads('this is where your big JSON blob goes') my_result = PingResult(my_result_dict) my_result.af # Returns 6 my_result.rtt_median # Returns 123.456 .. _use-agnostic-parsing: Agnostic Parsing ---------------- There may be a case where you have code that's just expected to parse a result string, without knowing ahead of time what type of result it is. For this we make use of the parent ``Result`` class' ``get()`` method:: from ripe.atlas.sagan import Result my_result = Result.get('this is where your big JSON blob goes') my_result.af # Returns 6 my_result.rtt_median # Returns 123.456 As you can see it works just like PingResult, but doesn't force you to know its type up front. Note that this does incur a small performance penalty however. .. _use-errors-and-malformations: Errors & Malformations ---------------------- RIPE Atlas, like the Internet is never 100% what you'd expect. Sometimes your measurement will return an error such as a timout or DNS lookup problem, and sometimes the data in a result might even be malformed on account of data corruption, damaged probe storage, etc. And like the most applications on the Internet, Sagan attemps to handle these inconsistencies gracefully. You can decide just how gracefully however. Say for example you've got a result that looks alright, but the ``abuf`` value is damaged in some way rendering it unreadable. You'll find that while the ``DnsResult`` object will not have a ``is_malformed=False``, the portion that is unreadable will be set to ``True``:: from ripe.atlas.sagan import DnsResult my_result = DnsResult('your JSON blob') my_result.is_error # False my_result.is_malformed # False my_result.responses[0].abuf.is_malformed # True my_result.responses[1].abuf.is_malformed # False You can control what you'd like Sagan to do in these cases by setting ``on_malformation=`` when parsing:: from ripe.atlas.sagan import DnsResult # Sets is_malformed=True and issues a warning my_result = DnsResult('your JSON blob') # Sets is_malformed=True my_result = DnsResult('your JSON blob', on_malformation=DnsResult.ACTION_IGNORE) # Sets explodes with a ResultParseError my_result = DnsResult('your JSON blob', on_malformation=DnsResult.ACTION_FAIL) Similarly, you can do the same thing with ``on_error=``, which perform the same way when Sagan encounters an error like a timeout or DNS lookup problem. Error handling is not yet complete in Sagan, so if you run across a case where it behaves in a way other than what you'd expect, please send a copy of the problematic result to atlas@ripe.net and we'll use it to update this library. .. _examples: Examples ======== .. _examples-file: Parsing Results out of a Local File ----------------------------------- Assume for a moment that you've downloaded a bunch of results into a local file using our *fragmented JSON* format. That is, you have in your possession a file that has a separate JSON result on every line. For the purposes of our example we'll call it ``file.txt``.:: from ripe.atlas.sagan import Result my_results_file = "/path/to/file.txt" with open(my_results_file) as results: for result in results.readlines(): parsed_result = Result.get(result) print(parsed_result.origin) Basically you use Python to open the file (using ``with``) and then loop over each line in the file (``.readlines()``), sending each line into Sagan which returns a ``parsed_result``. With that result, you can then pull out any of the values you like, using the :ref:`attributes-methods` documentation as a reference. .. _examples-api: Pulling Directly from the API ----------------------------- A common use case for the parser is to plug it into our RESTful API service. The process for this is pretty simple: fetch a bunch of results, loop over them, and for each one, apply the parser to get the value you want. Say for example you want to get the ``checksum`` value for each result from measurement `#1012449`_. To do this, we'll fetch the latest results from each probe via the ``measurement-latest`` API, and parse each one to get the checksum values:: import requests from ripe.atlas.sagan import SslResult source = "https://atlas.ripe.net/api/v1/measurement-latest/1012449/" response = requests.get(source).json for probe_id, result in response.items(): result = result[0] # There's only one result for each probe parsed_result = SslResult(result) # Parsing magic! # Each SslResult has n certificates for certificate in parsed_result.certificates: print(certificate.checksum) # Print the checksum for this certificate # Make use of the handy get_checksum_chain() to render the checksum of each certificate into one string if you want print(parsed_result.get_checksum_chain()) .. _#1012449: https://atlas.ripe.net/measurements/1012449/ .. _examples-types: Samples from Each Type ---------------------- .. _examples-types-ping: Ping .... For more information regarding all properties available, you should consult the :ref:`ping` section of this documentation.:: ping_result.packets_sent # Int ping_result.rtt_median # Float, rounded to 3 decimal places ping_result.rtt_average # Float, rounded to 3 decimal places .. _examples-types-traceroute: Traceroute .......... For more information regarding all properties available, you should consult the :ref:`traceroute` section of this documentation.:: traceroute_result.af # 4 or 6 traceroute_result.total_hops # Int traceroute_result.destination_address # An IP address string .. _examples-types-dns: DNS .... For more information regarding all properties available, you should consult the :ref:`dns` section of this documentation.:: dns_result.responses # A list of Response objects dns_result.responses[0].response_time # Float, rounded to 3 decimal places dns_result.responses[0].headers # A list of Header objects dns_result.responses[0].headers[0].nscount # The NSCOUNT value for the first header dns_result.responses[0].questions # A list of Question objects dns_result.responses[0].questions[0].type # The TYPE value for the first question dns_result.responses[0].abuf # The raw, unparsed abuf string .. _examples-types-sslcert: SSL Certificates ................ For more information regarding all properties available, you should consult the :ref:`sslcert` section of this documentation.:: ssl_result.af # 4 or 6 ssl_result.certificates # A list of Certificate objects ssl_result.certificates[0].checksum # The checksum for the first certificate .. _examples-types-http: HTTP .... For more information regarding all properties available, you should consult the :ref:`http` section of this documentation.:: http_result.af # 4 or 6 http_result.uri # A URL string http_result.responses # A list of Response objects http_result.responses[0].body_size # The size of the body of the first response ripe-atlas-sagan-1.3.1/ripe/000077500000000000000000000000001405365472700156205ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/ripe/__init__.py000066400000000000000000000015031405365472700177300ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . try: __import__('pkg_resources').declare_namespace(__name__) except ImportError: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) ripe-atlas-sagan-1.3.1/ripe/atlas/000077500000000000000000000000001405365472700167245ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/ripe/atlas/__init__.py000066400000000000000000000015031405365472700210340ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . try: __import__('pkg_resources').declare_namespace(__name__) except ImportError: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/000077500000000000000000000000001405365472700200155ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/__init__.py000066400000000000000000000021351405365472700221270ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from __future__ import absolute_import from .base import Result, ResultError, ResultParseError from .dns import DnsResult from .http import HttpResult from .ping import PingResult from .ssl import SslResult from .traceroute import TracerouteResult from .ntp import NtpResult from .version import __version__ __all__ = ( "Result", "PingResult", "TracerouteResult", "DnsResult", "SslResult", "HttpResult", "NtpResult", ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/base.py000066400000000000000000000214621405365472700213060ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import logging import pytz from calendar import timegm from datetime import datetime from .helpers.compatibility import string # Try to use ujson if it's available try: import ujson as json except ImportError: import json class ResultParseError(Exception): pass class ResultError(Exception): pass class Json(object): """ ujson, while impressive, is not a drop-in replacement for json as it doesn't respect the various keyword arguments permitted in the default json parser. As a workaround for this, we have our own class that defines its own .loads() method, so we can check for whichever we're using and adjust the arguments accordingly. """ @staticmethod def loads(*args, **kwargs): try: if json.__name__ == "ujson": return json.loads(*args, **kwargs) return json.loads(strict=False, *args, **kwargs) except ValueError: raise ResultParseError("The JSON result could not be parsed") class ParsingDict(object): """ A handy container for methods we use for validation in the various result classes. Note that Python 2.x and 3.x handle the creation of dictionary-like objects differently. If we write it this way, it works for both. """ ACTION_IGNORE = 1 ACTION_WARN = 2 ACTION_FAIL = 3 PROTOCOL_ICMP = "ICMP" PROTOCOL_UDP = "UDP" PROTOCOL_TCP = "TCP" PROTOCOL_MAP = { "ICMP": PROTOCOL_ICMP, "I": PROTOCOL_ICMP, "UDP": PROTOCOL_UDP, "U": PROTOCOL_UDP, "TCP": PROTOCOL_TCP, "T": PROTOCOL_TCP, } def __init__(self, **kwargs): self._on_error = kwargs.pop("on_error", self.ACTION_WARN) self.is_error = False self.error_message = None self._on_malformation = kwargs.pop("on_malformation", self.ACTION_WARN) self.is_malformed = False def __nonzero__(self): # If we don't define this, Python ends up calling keys() # via __len__() whenever we evaluate the object as a bool. return True def __len__(self): return len(self.keys()) def __iter__(self): for key in self.keys(): yield getattr(self, key) def __getitem__(self, key): return getattr(self, key) def __setitem__(self, key, item): setattr(self, key, item) def keys(self): return [p for p in dir(self) if self._is_property_name(p)] def ensure(self, key, kind, default=None): try: if kind == "datetime": return datetime.fromtimestamp( self.raw_data[key], tz=pytz.UTC) return kind(self.raw_data[key]) except (TypeError, ValueError, KeyError): return default def clean_protocol(self, protocol): """ A lot of measurement types make use of a protocol value, so we handle that here. """ if protocol is not None: try: return self.PROTOCOL_MAP[protocol] except KeyError: self._handle_malformation( '"{protocol}" is not a recognised protocol'.format( protocol=protocol ) ) def _handle_malformation(self, message): if self._on_malformation == self.ACTION_FAIL: raise ResultParseError(message) elif self._on_malformation == self.ACTION_WARN: logging.warning(message) self.is_malformed = True def _handle_error(self, message): if self._on_error == self.ACTION_FAIL: raise ResultError(message) elif self._on_error == self.ACTION_WARN: logging.warning(message) self.is_error = True self.error_message = message def _is_property_name(self, p): if not p.startswith("_"): if p not in ("keys",): if not p.upper() == p: if not callable(getattr(self, p)): return True return False class Result(ParsingDict): """ The parent class for all measurement result classes. Subclass this to handle parsing a new measurement type, or use .get() to let this class figure out the type for you. """ def __init__(self, data, *args, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data if isinstance(data, string): self.raw_data = Json.loads(data) for key in ("timestamp", "msm_id", "prb_id", "fw", "type"): if key not in self.raw_data: raise ResultParseError( "This doesn't look like a RIPE Atlas measurement: {}".format( self.raw_data ) ) self.created = datetime.fromtimestamp( self.raw_data["timestamp"], tz=pytz.UTC) self.measurement_id = self.ensure("msm_id", int) self.probe_id = self.ensure("prb_id", int) self.firmware = self.ensure("fw", int) self.origin = self.ensure("from", str) self.seconds_since_sync = self.ensure("lts", int) self.group_id = self.ensure("group_id", int) self.bundle = self.ensure("bundle", int) # Handle the weird case where fw=0 and we don't know what to expect if self.firmware == 0: self._handle_malformation("Unknown firmware: {fw}".format( fw=self.firmware) ) if self.seconds_since_sync is not None: if self.seconds_since_sync < 0: self.seconds_since_sync = None if "dnserr" in self.raw_data: self._handle_error(self.raw_data["dnserr"]) if "err" in self.raw_data: self._handle_error(self.raw_data["err"]) def __repr__(self): return "Measurement #{measurement}, Probe #{probe}".format( measurement=self.measurement_id, probe=self.probe_id ) @property def created_timestamp(self): return timegm(self.created.timetuple()) @classmethod def get(cls, data, **kwargs): """ Call this when you have a JSON result and just want to turn it into the appropriate Result subclass. This is less performant than calling PingResult(json_string) directly however, as the JSON has to be parsed first to find the type. """ raw_data = data if isinstance(data, string): raw_data = Json.loads(data) try: kind = raw_data["type"].lower() except KeyError: raise ResultParseError("No type value was found in the JSON input") if kind == "ping": from .ping import PingResult return PingResult(raw_data, **kwargs) elif kind == "traceroute": from .traceroute import TracerouteResult return TracerouteResult(raw_data, **kwargs) elif kind == "dns": from .dns import DnsResult return DnsResult(raw_data, **kwargs) elif kind == "sslcert": from .ssl import SslResult return SslResult(raw_data, **kwargs) elif kind == "http": from .http import HttpResult return HttpResult(raw_data, **kwargs) elif kind == "ntp": from .ntp import NtpResult return NtpResult(raw_data, **kwargs) elif kind == "wifi": from .wifi import WiFiResult return WiFiResult(raw_data, **kwargs) raise ResultParseError("Unknown type value was found in the JSON input") @staticmethod def calculate_median(given_list): """ Returns the median of values in the given list. """ median = None if not given_list: return median given_list = sorted(given_list) list_length = len(given_list) if list_length % 2: median = given_list[int(list_length / 2)] else: median = (given_list[int(list_length / 2)] + given_list[int(list_length / 2) - 1]) / 2.0 return median @property def type(self): return self.__class__.__name__.replace("Result", "").lower() __all__ = ( "Result", "ResultParseError", ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/dns.py000066400000000000000000000566341405365472700211710ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from __future__ import absolute_import import base64 from collections import namedtuple from datetime import datetime from pytz import UTC from .base import Result, ParsingDict from .helpers import abuf from .helpers import compatibility class Header(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.aa = self.ensure("AA", bool) self.qr = self.ensure("QR", bool) self.nscount = self.ensure("NSCOUNT", int) self.qdcount = self.ensure("QDCOUNT", int) self.ancount = self.ensure("ANCOUNT", int) self.tc = self.ensure("TC", bool) self.rd = self.ensure("RD", bool) self.arcount = self.ensure("ARCOUNT", int) self.return_code = self.ensure("ReturnCode", str) self.opcode = self.ensure("OpCode", str) self.ra = self.ensure("RA", bool) self.z = self.ensure("Z", int) self.ad = self.ensure("AD", bool) self.cd = self.ensure("CD", bool) self.id = self.ensure("ID", int) def __str__(self): return "Header: " + self.return_code @property def flags(self): flags = namedtuple( "Flags", ("qr", "aa", "tc", "rd", "ra", "z", "ad", "cd")) return flags(qr=self.qr, aa=self.aa, tc=self.tc, rd=self.rd, ra=self.ra, z=self.z, ad=self.ad, cd=self.cd) @property def sections(self): sections = namedtuple( "Sections", ("QDCOUNT", "ANCOUNT", "NSCOUNT", "ARCOUNT")) return sections(QDCOUNT=self.qdcount, ANCOUNT=self.ancount, NSCOUNT=self.nscount, ARCOUNT=self.arcount) @property def is_authoritative(self): return self.aa @property def is_query(self): if self.qr is None: return None return not self.qr @property def nameserver_count(self): """ Otherwise known as the NSCOUNT or the authority_count. """ return self.nscount @property def question_count(self): return self.qdcount @property def answer_count(self): return self.ancount @property def is_truncated(self): return self.tc @property def recursion_desired(self): return self.rd @property def additional_count(self): return self.arcount @property def recursion_available(self): return self.ra @property def zero(self): return self.z @property def checking_disabled(self): return self.cd @property def authenticated_data(self): return self.aa class Option(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.nsid = self.ensure("NSID", str) self.code = self.ensure("OptionCode", int) self.length = self.ensure("OptionLength", int) self.name = self.ensure("OptionName", str) class Edns0(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.extended_return_code = self.ensure("ExtendedReturnCode", int) self.name = self.ensure("Name", str) self.type = self.ensure("Type", str) self.udp_size = self.ensure("UDPsize", int) self.version = self.ensure("Version", int) self.z = self.ensure("Z", int) self.do = bool(self.ensure("DO", bool)) self.options = [] if "Option" in self.raw_data: if isinstance(self.raw_data["Option"], list): for option in self.raw_data["Option"]: self.options.append(Option(option)) class Question(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.klass = self.ensure("Qclass", str) self.type = self.ensure("Qtype", str) self.name = self.ensure("Qname", str) def __str__(self): return ";{:30} {:<5} {:5}".format(self.name, self.klass, self.type) class Answer(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.name = self.ensure("Name", str) self.ttl = self.ensure("TTL", int) self.type = self.ensure("Type", str) self.klass = self.ensure("Class", str) self.rd_length = self.ensure("RDlength", int) # Where data goes when the abuf parser can't understand things self.rdata = self.ensure("Rdata", str) @property def resource_data_length(self): return self.rd_length def __str__(self): return "{:22} {:<7} {:5} {:5}".format( self.name, self.ttl, self.klass, self.type ) class AAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.address = self.ensure("Address", str) def __str__(self): return "{0} {1}".format(Answer.__str__(self), self.address) class AaaaAnswer(AAnswer): pass class NsAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.target = self.ensure("Target", str) def __str__(self): return "{0} {1}".format(Answer.__str__(self), self.target) class CnameAnswer(NsAnswer): pass class MxAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.preference = self.ensure("Preference", int) self.mail_exchanger = self.ensure("MailExchanger", str) def __str__(self): return "{0} {1} {2}".format( Answer.__str__(self), self.preference, self.mail_exchanger ) class SoaAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.mname = self.ensure("MasterServerName", str) self.rname = self.ensure("MaintainerName", str) self.serial = self.ensure("Serial", int) self.refresh = self.ensure("Refresh", int) self.retry = self.ensure("Retry", int) self.expire = self.ensure("Expire", int) self.minimum = self.ensure("NegativeTtl", int) def __str__(self): return "{0} {1} {2} {3} {4} {5} {6} {7}".format( Answer.__str__(self), self.mname, self.rname, self.serial, self.refresh, self.retry, self.expire, self.minimum ) @property def master_server_name(self): return self.mname @property def maintainer_name(self): return self.rname @property def negative_ttl(self): return self.minimum @property def nxdomain(self): return self.minimum class DsAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.tag = self.ensure("Tag", int) self.algorithm = self.ensure("Algorithm", int) self.digest_type = self.ensure("DigestType", int) self.delegation_key = self.ensure("DelegationKey", str) def __str__(self): return "{0} {1} {2} {3} {4}".format( Answer.__str__(self), self.tag, self.algorithm, self.digest_type, self.delegation_key ) class DnskeyAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.flags = self.ensure("Flags", int) self.algorithm = self.ensure("Algorithm", int) self.protocol = self.ensure("Protocol", int) self.key = self.ensure("Key", str) def __str__(self): return "{0} {1} {2} {3} {4}".format( Answer.__str__(self), self.flags, self.algorithm, self.protocol, self.key ) class TxtAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.data = [] if "Data" in self.raw_data: if isinstance(self.raw_data["Data"], list): self.data = [] for s in self.raw_data["Data"]: if isinstance(s, compatibility.string): self.data.append(s) def __str__(self): return "{0} {1}".format(Answer.__str__(self), self.data_string) @property def data_string(self): return " ".join(self.data) class RRSigAnswer(Answer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.type_covered = self.ensure("TypeCovered", str) self.algorithm = self.ensure("Algorithm", int) self.labels = self.ensure("Labels", int) self.original_ttl = self.ensure("OriginalTTL", int) self.signature_expiration = self.ensure("SignatureExpiration", int) self.signature_inception = self.ensure("SignatureInception", int) self.key_tag = self.ensure("KeyTag", int) self.signer_name = self.ensure("SignerName", str) self.signature = self.ensure("Signature", str) def __str__(self): formatter = "%Y%m%d%H%M%S" expiration = datetime.fromtimestamp( self.signature_expiration, tz=UTC).strftime(formatter) inception = datetime.fromtimestamp( self.signature_inception, tz=UTC).strftime(formatter) return "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}".format( Answer.__str__(self), self.type_covered, self.algorithm, self.labels, self.original_ttl, expiration, inception, self.key_tag, self.signer_name, self.signature ) class NotFullySupportedAnswer(Answer): """ We're still working on getting the proper text representations of some Answer classes, so such classes will inherit from this one. """ def __str__(self): return "{0} ---- Not fully supported ----".format(Answer.__str__(self)) class NsecAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.next_domain_name = self.ensure("NextDomainName", str) self.types = self.ensure("Types", list) class Nsec3Answer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.hash_algorithm = self.ensure("HashAlg", int) self.flags = self.ensure("Flags", int) self.iterations = self.ensure("Iterations", int) self.salt = self.ensure("Salt", str) self.hash = self.ensure("Hash", str) self.types = self.ensure("Types", list) class Nsec3ParamAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.algorithm = self.ensure("Algorithm", int) self.flags = self.ensure("Flags", int) self.iterations = self.ensure("Iterations", int) self.salt = self.ensure("Salt", str) class PtrAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.target = self.ensure("Target", str) class SrvAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.priority = self.ensure("Priority", int) self.weight = self.ensure("Weight", int) self.port = self.ensure("Port", int) self.target = self.ensure("Target", str) class SshfpAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.algorithm = self.ensure("Algorithm", int) self.digest_type = self.ensure("DigestType", int) self.fingerprint = self.ensure("Fingerprint", str) class TlsaAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.certificate_usage = self.ensure("CertUsage", int) self.selector = self.ensure("Selector", int) self.matching_type = self.ensure("MatchingType", int) self.certificate_associated_data = self.ensure("CertAssData", str) class HinfoAnswer(NotFullySupportedAnswer): def __init__(self, data, **kwargs): Answer.__init__(self, data, **kwargs) self.cpu = self.ensure("Cpu", str) self.os = self.ensure("Os", str) class Message(ParsingDict): ANSWER_CLASSES = { "A": AAnswer, "AAAA": AaaaAnswer, "NS": NsAnswer, "CNAME": CnameAnswer, "MX": MxAnswer, "SOA": SoaAnswer, "DS": DsAnswer, "DNSKEY": DnskeyAnswer, "TXT": TxtAnswer, "RRSIG": RRSigAnswer, "NSEC": NsecAnswer, "NSEC3": Nsec3Answer, "NSEC3PARAM": Nsec3ParamAnswer, "PTR": PtrAnswer, "SRV": SrvAnswer, "SSHFP": SshfpAnswer, "TLSA": TlsaAnswer, "HINFO": HinfoAnswer } def __init__(self, message, response_data, parse_buf=True, **kwargs): ParsingDict.__init__(self, **kwargs) self._string_representation = message self.raw_data = {} if parse_buf: self._parse_buf(message) else: self._backfill_raw_data_from_result(response_data) self.header = None if "HEADER" in self.raw_data: self.header = Header(self.raw_data["HEADER"], **kwargs) # This is a tricky one, since you can't know that the response is an # error until *after* the abuf is parsed, and it won't be parsed # until you attempt to access it. code = self.header.return_code if not code or code.upper() != "NOERROR": self._handle_error('The response did not contain "NOERROR"') self.edns0 = None self.questions = [] self.answers = [] self.authorities = [] self.additionals = [] if "EDNS0" in self.raw_data: self.edns0 = Edns0(self.raw_data["EDNS0"], **kwargs) for question in self.raw_data.get("QuestionSection", []): self.questions.append(Question(question, **kwargs)) for answer in self.raw_data.get("AnswerSection", []): self._append_answer(answer, "answers", **kwargs) for authority in self.raw_data.get("AuthoritySection", []): self._append_answer(authority, "authorities", **kwargs) for additional in self.raw_data.get("AdditionalSection", []): self._append_answer(additional, "additionals", **kwargs) def __str__(self): return self._string_representation def __repr__(self): return str(self) def _append_answer(self, answer, section, **kwargs): answer_type = answer.get("Type") if answer_type is None: self._handle_malformation( "Answer has no parseable Type: {answer}".format( answer=answer ) ) answer_class = self.ANSWER_CLASSES.get(answer_type, Answer) getattr(self, section).append(answer_class(answer, **kwargs)) def _parse_buf(self, message): try: self.raw_data = abuf.AbufParser.parse(base64.b64decode(message)) except Exception as e: self.raw_data = {} self._handle_malformation( "{exception}: Unable to parse buffer: {buffer}".format( exception=e, buffer=self._string_representation ) ) else: if "ERROR" in self.raw_data: self._handle_error(self.raw_data["ERROR"]) def _backfill_raw_data_from_result(self, response_data): # Header self.raw_data["Header"] = {} for key in ("NSCOUNT", "QDCOUNT", "ID", "ARCOUNT", "ANCOUNT"): if key in response_data: self.raw_data["Header"][key] = response_data[key] # Answers if "answers" in response_data and response_data["answers"]: # The names used in the result don't align to those used in the abuf # parser name_map = { "TTL": "TTL", "TYPE": "Type", "NAME": "Name", "RDATA": "Data", "MNAME": "MasterServerName", "RNAME": "MaintainerName", "SERIAL": "Serial", "RDLENGTH": "RDlength", } self.raw_data["AnswerSection"] = [] for answer in response_data["answers"]: temporary = {} for k, v in name_map.items(): if k in answer: temporary[v] = answer[k] # Special case where some older txt entires are strings and not # a list if temporary.get("Type") == "TXT": if isinstance(temporary.get("Data"), compatibility.string): temporary["Data"] = [temporary["Data"]] if temporary: self.raw_data["AnswerSection"].append(temporary) class Response(ParsingDict): def __init__(self, data, af=None, destination=None, source=None, protocol=None, part_of_set=True, parse_buf=True, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.af = self.ensure("af", int, af) self.destination_address = self.ensure("dst_addr", str, destination) self.source_address = self.ensure("src_addr", str, source) self.protocol = self.ensure("proto", str, protocol) self.response_id = None # Preparing for lazy stuff self._abuf = None self._qbuf = None self._parse_buf = parse_buf try: self.response_time = round(float(self.raw_data["result"]["rt"]), 3) except KeyError: try: self.response_time = round(self.ensure("rt", float), 3) except TypeError: self.response_time = None try: self.response_size = self.raw_data["result"]["size"] except KeyError: self.response_size = self.ensure("size", int) if part_of_set: self.response_id = self.ensure("subid", int) if self.protocol and isinstance(self.protocol, str): self.protocol = self.clean_protocol(self.protocol) @property def abuf(self): return self._get_buf("a") @property def qbuf(self): return self._get_buf("q") def _get_buf(self, prefix): """ Lazy read-only accessor for the (a|q)buf. The qbuf Message object is cached for subsequent requests. """ kind = "{prefix}buf".format(prefix=prefix) private_name = "_" + kind buf = getattr(self, private_name) if buf: return buf try: buf_string = self.raw_data["result"][kind] except KeyError: buf_string = self.ensure(kind, str) if buf_string: message = Message( buf_string, self.raw_data, parse_buf=self._parse_buf, on_error=self._on_error, on_malformation=self._on_malformation ) if message.is_error: self._handle_error(message.error_message) setattr(self, private_name, message) return getattr(self, private_name) class DnsResult(Result): def __init__(self, data, parse_buf=True, **kwargs): """ Note that we're not setting `self.af` here, but rather we have it as a property of `Response` as it's possible that one result can contain multiple responses, each with either af=4 or af=6. """ Result.__init__(self, data, **kwargs) self.responses = [] self.responses_total = None af = self.ensure("af", int) protocol = self.ensure("proto", str) source_address = self.ensure("src_addr", str) destination_address = self.ensure("dst_addr", str) if 0 < self.firmware < 4460: af = self.ensure("pf", int) part_of_set, responses = self.build_responses() for response in responses: self.responses.append(Response( response, af=af, destination=destination_address, source=source_address, protocol=protocol, part_of_set=part_of_set, parse_buf=parse_buf, **kwargs )) if "error" in self.raw_data: if isinstance(self.raw_data["error"], dict): if "timeout" in self.raw_data["error"]: self._handle_error("Timeout: {timeout}".format( timeout=self.raw_data["error"]["timeout"] )) elif "getaddrinfo" in self.raw_data["error"]: self._handle_error("Name resolution error: {msg}".format( msg=self.raw_data["error"]["getaddrinfo"] )) else: self._handle_error("Unknown error: {msg}".format( msg=self.raw_data["error"] )) else: self._handle_error("Unknown error: {msg}".format( msg=self.raw_data["error"] )) def build_responses(self): """ DNS measurement results are a little wacky. Sometimes you get a single response, other times you get a set of responses (result set). In order to establish a unified interface, we conform all results to the same format: a list of response objects. Additionally, the qbuf property is weird too. In the case of multiple responses, there's one qbuf for every response, but for single results, it's not stored in the result, but rather the outer result data. Again, for the purposes of uniformity, we shoehorn the qbuf into the first (and only) response in the latter case. """ responses = [] part_of_set = True # Account for single results if "result" in self.raw_data: if "qbuf" in self.raw_data: if "qbuf" not in self.raw_data["result"]: self.raw_data["result"]["qbuf"] = self.raw_data.pop("qbuf") responses.append(self.raw_data["result"]) part_of_set = False try: self.responses_total = int(self.raw_data["result"]["submax"]) except (KeyError, ValueError): pass # The value wasn't there, not much we can do about it try: responses += self.raw_data["resultset"] except KeyError: pass # self.responses remains the same return part_of_set, responses __all__ = ( "DnsResult", ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/helpers/000077500000000000000000000000001405365472700214575ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/helpers/__init__.py000066400000000000000000000012331405365472700235670ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/helpers/abuf.py000066400000000000000000000743301405365472700227550ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from __future__ import absolute_import import base64 import codecs import struct def base64_encodebytes(data): if hasattr(base64, "encodebytes"): return base64.encodebytes(data) return base64.encodestring(data) class AbufParser(object): DNS_CTYPE = "ASCII" @classmethod def parse(cls, buf, options=None): """ According to Philip, an abuf is like a TARDIS: it's bigger on the inside """ error = [] do_header = True do_question = True do_answer = True do_authority = True do_additional = True do_options = True if options and isinstance(options, dict): if 'DO_Header' in options and not options['DO_Header']: do_header = options['DO_Header'] if 'DO_Question' in options and not options['DO_Question']: do_question = options['DO_Question'] if 'DO_Answer' in options and not options['DO_Answer']: do_answer = options['DO_Answer'] if 'DO_Authority' in options and not options['DO_Authority']: do_authority = options['DO_Authority'] if 'DO_Additional' in options and not options['DO_Additional']: do_additional = options['DO_Additional'] if 'DO_Options' in options and not options['DO_Options']: do_options = options['DO_Options'] dnsres = {} offset = 0 offset, hdr = cls._parse_header(buf, offset, error) if do_header: dnsres['HEADER'] = hdr for i in range(hdr['QDCOUNT']): res = cls._do_query(buf, offset, error) if res is None: e = ('additional', offset, ('_do_query failed, additional record %d' % i)) error.append(e) dnsres['ERROR'] = error return dnsres offset, qry = res if do_question: if i == 0: dnsres['QuestionSection'] = [qry] else: dnsres['QuestionSection'].append(qry) for i in range(hdr['ANCOUNT']): res = cls._do_rr(buf, offset, error, hdr) if res is None: e = ('additional', offset, ('_do_rr failed, additional record %d' % i)) error.append(e) dnsres['ERROR'] = error return dnsres offset, rr = res if do_answer: if i == 0: dnsres['AnswerSection'] = [rr] else: dnsres['AnswerSection'].append(rr) for i in range(hdr['NSCOUNT']): res = cls._do_rr(buf, offset, error, hdr) if res is None: e = ('additional', offset, ('_do_rr failed, additional record %d' % i)) error.append(e) dnsres['ERROR'] = error return dnsres offset, rr = res if do_authority: if i == 0: dnsres['AuthoritySection'] = [rr] else: dnsres['AuthoritySection'].append(rr) for i in range(hdr['ARCOUNT']): res = cls._do_rr(buf, offset, error, hdr) if res is None: e = ('additional', offset, ('_do_rr failed, additional record %d' % i)) error.append(e) dnsres['ERROR'] = error return dnsres offset, rr = res if do_options: if "EDNS0" in rr: dnsres['EDNS0'] = rr['EDNS0'] continue if do_additional: if 'AdditionalSection' in dnsres: dnsres['AdditionalSection'].append(rr) else: dnsres['AdditionalSection'] = [rr] hdr['ReturnCode'] = cls._rcode_to_text(hdr['ReturnCode']) if offset < len(buf): e = ('end', offset, 'trailing garbage, buf size = %d' % len(buf)) error.append(e) #result['decodedabufs_with_ERROR'] += 1 dnsres['ERROR'] = error return dnsres @staticmethod def _opcode_to_text(opcode): return { 0: 'QUERY', 1: 'IQUERY', 2: 'STATUS', 4: 'NOTIFY', 5: 'UPDATE'}.get(opcode, opcode) @staticmethod def _class_to_text(rdataclass): return {0: 'RESERVED0', 1: 'IN', 3: 'CH', 4: 'HS', 254: 'NONE', 255: 'ANY'}.get(rdataclass, rdataclass) @staticmethod def _rcode_to_text(rcode): return {0: 'NOERROR', 1: 'FORMERR', 2: 'SERVFAIL', 3: 'NXDOMAIN', 4: 'NOTIMP', 5: 'REFUSED', 6: 'YXDOMAIN', 7: 'YXRRSET', 8: 'NXRRSET', 9: 'NOTAUTH', 10: 'NOTZONE', 16: 'BADVERS', 23: 'BADCOOKIE'}.get(rcode, rcode) @staticmethod def _type_to_text(rdatatype): return {0: 'NONE', 1: 'A', 2: 'NS', 3: 'MD', 4: 'MF', 5: 'CNAME', 6: 'SOA', 7: 'MB', 8: 'MG', 9: 'MR', 10: 'NULL', 11: 'WKS', 12: 'PTR', 13: 'HINFO', 14: 'MINFO', 15: 'MX', 16: 'TXT', 17: 'RP', 18: 'AFSDB', 19: 'X25', 20: 'ISDN', 21: 'RT', 22: 'NSAP', 23: 'NSAP_PTR', 24: 'SIG', 25: 'KEY', 26: 'PX', 27: 'GPOS', 28: 'AAAA', 29: 'LOC', 30: 'NXT', 33: 'SRV', 35: 'NAPTR', 36: 'KX', 37: 'CERT', 38: 'A6', 39: 'DNAME', 41: 'OPT', 42: 'APL', 43: 'DS', 44: 'SSHFP', 45: 'IPSECKEY', 46: 'RRSIG', 47: 'NSEC', 48: 'DNSKEY', 49: 'DHCID', 50: 'NSEC3', 51: 'NSEC3PARAM', 52: 'TLSA', 55: 'HIP', 99: 'SPF', 103: 'UNSPEC', 249: 'TKEY', 250: 'TSIG', 251: 'IXFR', 252: 'AXFR', 253: 'MAILB', 254: 'MAILA', 255: 'ANY', 32768: 'TA', 32769: 'DLV'}.get(rdatatype, rdatatype) @classmethod def _bytes_as_hex_str(cls, b): b_as_hex = codecs.getencoder('hex_codec')(b)[0] b_as_hex_str = b_as_hex.decode(cls.DNS_CTYPE) return b_as_hex_str @classmethod def _types_bitmap(cls, data, error): bits = [] o = 0 while o < len(data): fmt = "!BB" fmtsz = struct.calcsize(fmt) dat = data[o:o+fmtsz] if len(dat) != fmtsz: e = ("_types_bitmap", o, 'offset out of range: data size = %d' % len(data)) error.append(e) return None block, bytes = struct.unpack(fmt, dat) o += fmtsz for i in range(bytes): b = struct.unpack("!B", data[o+i:o+i+1])[0] for j in range(8): if b & (1 << (7-j)): bits.append((block*32+i)*8+j) o += bytes return bits @classmethod def _parse_header(cls, buf, offset, error): fmt = "!HHHHHH" reqlen = struct.calcsize(fmt) strng = buf[offset:offset + reqlen] if len(strng) != reqlen: e = ("_parse_header", offset, 'offset out of range: buf size = %d' % len(buf)) error.append(e) return None res = struct.unpack(fmt, strng) hdr = { "ID": res[0] } qr = 0x8000 opcode_mask = 0x7800 opcode_shift = 11 aa = 0x0400 tc = 0x0200 rd = 0x0100 ra = 0x0080 z_mask = 0x0040 z_shift = 6 ad = 0x0020 cd = 0x0010 rcode_mask = 0x000F rcode_shift = 0 hdr['QR'] = bool(res[1] & qr) hdr['OpCode'] = cls._opcode_to_text((res[1] & opcode_mask) >> opcode_shift) hdr['AA'] = bool(res[1] & aa) hdr['TC'] = bool(res[1] & tc) hdr['RD'] = bool(res[1] & rd) hdr['RA'] = bool(res[1] & ra) hdr['Z'] = (res[1] & z_mask) >> z_shift hdr['AD'] = bool(res[1] & ad) hdr['CD'] = bool(res[1] & cd) hdr['ReturnCode'] = ((res[1] & rcode_mask) >> rcode_shift) hdr['QDCOUNT'] = res[2] hdr['ANCOUNT'] = res[3] hdr['NSCOUNT'] = res[4] hdr['ARCOUNT'] = res[5] return offset + reqlen, hdr @classmethod def _do_query(cls, buf, offset, error): qry = {} res = cls._do_name(buf, offset, 0, error) if res is None: e = ("_do_query", offset, "_do_name failed") error.append(e) return None offset, name = res qry['Qname'] = name fmt = "!HH" reqlen = struct.calcsize(fmt) strng = buf[offset:offset + reqlen] if len(strng) != reqlen: e = ("_do_query", offset, 'offset out of range: buf size = %d' % len(buf)) error.append(e) return None res = struct.unpack(fmt, strng) qry['Qtype'] = cls._type_to_text(res[0]) qry['Qclass'] = cls._class_to_text(res[1]) return offset + reqlen, qry @classmethod def _clean_up_string(cls, strng): result = '' strng = bytearray(strng) for o in strng: if o < ord(' ') or o > ord('~'): result += ("\\%03d" % o) elif o == ord('"') or o == ord('\\'): result += "\\" + chr(o) else: result += chr(o) return result @classmethod def _do_rr(cls, buf, offset, error, hdr): edns0_opt_nsid = 3 # this is also hardcoded in dns.edns.py edns0_opt_client_subnet = 8 edns0_opt_cookies = 10 ClientCookieLenght = 8 ServerCookieMinLength = 8 ServerCookieMaxLength = 32 rr = {} res = cls._do_name(buf, offset, 0, error) if res is None: e = ("_do_rr", offset, "_do_name failed") error.append(e) return None offset, name = res rr['Name'] = name fmt = "!HHIH" reqlen = struct.calcsize(fmt) dat = buf[offset:offset + reqlen] if len(dat) != reqlen: e = ("_do_rr", offset, 'offset out of range: buf size = %d' % len(buf)) error.append(e) return None res = struct.unpack(fmt, dat) rr['Type'] = cls._type_to_text(res[0]) rr['Class'] = cls._class_to_text(res[1]) rr['TTL'] = res[2] rr['RDlength'] = res[3] offset += reqlen rdata = buf[offset:offset + rr['RDlength']] rdata_offset = offset offset = offset + rr['RDlength'] if rr['Type'] == 'OPT': # this is per cls._type_to_text function edns0 = { 'UDPsize': res[1], 'ExtendedReturnCode': res[2] >> 24, 'Version': (res[2] & 0x00ff0000) >> 16, 'Z': (res[2] & 0x007fff), 'Type': 'OPT', 'Option': [], 'Name': name, } if res[2] & 0x8000: edns0['DO']= True if edns0['ExtendedReturnCode'] != 0: # Compute new ReturnCode extended_rcode_shift = 4 hdr['ReturnCode'] |= \ edns0['ExtendedReturnCode'] << extended_rcode_shift o = 0 while o < len(rdata): fmt = "!HH" reqlen = struct.calcsize(fmt) dat = rdata[o:o + reqlen] if len(dat) != reqlen: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None res = struct.unpack(fmt, dat) opt = { 'OptionCode': res[0], 'OptionLength': res[1], } o += reqlen if opt['OptionCode'] == edns0_opt_nsid: opt['OptionName'] = 'NSID' nsid = rdata[o:o + opt['OptionLength']] nsid_as_str = nsid.decode(cls.DNS_CTYPE) opt[opt['OptionName']] = nsid_as_str if opt['OptionCode'] == edns0_opt_client_subnet: opt['OptionName'] = 'ClientSubnet' fmt = "!HBB" reqlen = struct.calcsize(fmt) dat = rdata[o:o + reqlen] if reqlen > len(dat): e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None res = struct.unpack(fmt, dat) opt['Family'] = {1: 'IPv4', 2: 'IPv6'}.get(res[0], res[0]) opt['SourcePrefixLength'] = res[1] opt['ScopePrefixLength'] = res[2] prefixlen= (res[1]+7)/8 prefix= rdata[o+reqlen:o+opt['OptionLength']] if len(prefix) != prefixlen: e = ("_do_rr", rdata_offset, 'wrong prefix length: rdata size = %d, required %d' % (len(prefix), prefixlen)) error.append(e) return None if res[0] == 1: # IPv4 prefix += b'\0' * (4-prefixlen) opt['Prefix'] = '.'.join(str(byte) \ for byte in struct.unpack("BBBB", prefix)) elif res[0] == 2: # IPv6 prefix += b'\0' * (16-prefixlen) fmt = "!HHHHHHHH" opt['Prefix'] = ':'.join(("%x" % quad) \ for quad in struct.unpack(fmt, prefix)) if opt['OptionCode'] == edns0_opt_cookies: opt['OptionName'] = 'Cookies' if opt['OptionLength'] >= ClientCookieLenght: opt['ClientCookie'] = cls._bytes_as_hex_str( \ rdata[o:o + ClientCookieLenght]) if ServerCookieMinLength <= \ opt['OptionLength']-ClientCookieLenght <= \ ServerCookieMaxLength: opt['ServerCookie'] = cls._bytes_as_hex_str( \ rdata[o+ClientCookieLenght : \ o+opt['OptionLength']]) o = o + opt['OptionLength'] edns0['Option'].append(opt) del rr['Class'] del rr['RDlength'] del rr['TTL'] del rr['Name'] del rr['Type'] rr['EDNS0'] = edns0 return offset, rr if rr['Class'] == "IN": # this is per cls._type_to_text function if rr['Type'] == 'A': fmt = "!BBBB" reqlen = struct.calcsize(fmt) if reqlen > len(rdata): e = ("_do_rr", rdata_offset, 'rdata too small: size = %d' % len(rdata)) error.append(e) return None rr['Address'] = '.'.join(str(byte) for byte in struct.unpack(fmt, rdata)) elif rr['Type'] == 'AAAA': fmt = "!HHHHHHHH" reqlen = struct.calcsize(fmt) if reqlen > len(rdata): e = ("_do_rr", rdata_offset, 'rdata too small: size = %d' % len(rdata)) error.append(e) return None addr = ':'.join(("%x" % quad) for quad in struct.unpack(fmt, rdata)) rr['Address'] = addr elif rr['Type'] == 'CNAME': doffset, name = cls._do_name(buf, rdata_offset, 0, error) rr['Target'] = name elif rr['Type'] == 'DNSKEY': fmt = '!HBB' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['Flags'], rr['Protocol'], rr['Algorithm'] =\ struct.unpack(fmt, dat) key = rdata[struct.calcsize(fmt):] key_as_base64 = base64_encodebytes(key) key_as_base64_str = key_as_base64.decode(cls.DNS_CTYPE) rr['Key'] = ''.join(key_as_base64_str.split()) elif rr['Type'] == 'DS': fmt = '!HBB' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['Tag'], rr['Algorithm'], rr['DigestType'] = \ struct.unpack(fmt, dat) key = rdata[struct.calcsize(fmt):] rr['DelegationKey'] = cls._bytes_as_hex_str(key) elif rr['Type'] == 'HINFO': fmt = "!B" fmtsz = struct.calcsize(fmt) o = 0 for tag in ('Cpu', 'Os'): dat = rdata[o:o+fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None o += fmtsz slen = struct.unpack(fmt, dat)[0] strng = rdata[o:o+slen] if len(strng) < slen: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr[tag] = cls._clean_up_string(strng) o += slen elif rr['Type'] == 'MX': fmt = '!H' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['Preference'] = struct.unpack(fmt, dat)[0] rr_offset, rr['MailExchanger'] = cls._do_name(buf, rdata_offset + fmtsz, 0, error) elif rr['Type'] == 'NS': res = cls._do_name(buf, rdata_offset, 0, error) if res is None: e = ("_do_rr", offset, "_do_name failed") error.append(e) return None doffset, name = res rr['Target'] = name elif rr['Type'] == 'NSEC': doffset, name = cls._do_name(buf, rdata_offset, 0, error) rr['NextDomainName'] = name o = doffset-rdata_offset bits = cls._types_bitmap(rdata[o:rr['RDlength']], error) if bits is None: e = ("_do_rr", 'failed to parse types bitmap') error.append(e) return None rr['Types'] = bits elif rr['Type'] == 'NSEC3': fmt = '!BBHB' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['HashAlg'], rr['Flags'], rr['Iterations'], SaltLength = struct.unpack(fmt, dat) o = fmtsz salt = rdata[o:o+SaltLength] rr['Salt']= cls._bytes_as_hex_str(salt) o += SaltLength fmt = '!B' fmtsz = struct.calcsize(fmt) dat = rdata[o:o+fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None HashLength = struct.unpack(fmt, dat)[0] o += fmtsz hash = rdata[o:o+HashLength] b32str = base64.b32encode(hash) while b32str[-1] == '=': b32str = b32str[:-1] # Note that we need extended hexadecimal instead of actual base32 # Just remap the input hexmap = { 'A': '0', 'B': '1', 'C': '2', 'D': '3', 'E': '4', 'F': '5', 'G': '6', 'H': '7', 'I': '8', 'J': '9', 'K': 'a', 'L': 'b', 'M': 'c', 'N': 'd', 'O': 'e', 'P': 'f', 'Q': 'g', 'R': 'h', 'S': 'i', 'T': 'j', 'U': 'k', 'V': 'l', 'W': 'm', 'X': 'n', 'Y': 'o', 'Z': 'p', '2': 'q', '3': 'r', '4': 's', '5': 't', '6': 'u', '7': 'v' } b32str = ''.join([hexmap[l] for l in b32str.decode(cls.DNS_CTYPE) ]) rr['Hash'] = b32str o += HashLength bits = cls._types_bitmap(rdata[o:rr['RDlength']], error) if bits is None: e = ("_do_rr", 'failed to parse types bitmap') error.append(e) return None rr['Types'] = bits elif rr['Type'] == 'NSEC3PARAM': fmt = '!BBHB' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['Algorithm'], rr['Flags'], rr['Iterations'], SaltLength = struct.unpack(fmt, dat) o = fmtsz salt = rdata[o:o+SaltLength] rr['Salt'] = cls._bytes_as_hex_str(salt) o += SaltLength elif rr['Type'] == 'PTR': doffset, name = cls._do_name(buf, rdata_offset, 0, error) rr['Target'] = name elif rr['Type'] == 'RRSIG': # https://tools.ietf.org/html/rfc4034#section-3.1 """ The RDATA for an RRSIG RR consists of a 2 octet Type Covered field, a 1 octet Algorithm field, a 1 octet Labels field, a 4 octet Original TTL field, a 4 octet Signature Expiration field, a 4 octet Signature Inception field, a 2 octet Key tag, the Signer's Name field, and the Signature field. """ fmt = "!HBBIIIH" fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['TypeCovered'], rr['Algorithm'], rr['Labels'], rr['OriginalTTL'], rr['SignatureExpiration'], rr['SignatureInception'], rr['KeyTag'] = struct.unpack(fmt, dat) rr['TypeCovered'] = cls._type_to_text( rr['TypeCovered'] ) res = cls._do_name(rdata, fmtsz, 0, error) if res is None: e = ("_do_rr", offset, "_do_name failed") error.append(e) return None signature_offset, rr['SignerName'] = res sig = rdata[signature_offset:] #sig_as_base64 = base64.encodebytes(sig) sig_as_base64 = base64_encodebytes(sig) sig_as_base64_str = sig_as_base64.decode(cls.DNS_CTYPE) rr['Signature'] = ''.join(sig_as_base64_str.split()) elif rr['Type'] == 'SOA': offset_name = cls._do_name(buf, rdata_offset, 0, error) if offset_name is None: e = ("do_rr", rdata_offset, '_do_name failed') error.append(e) return None rr_offset, rr['MasterServerName'] = offset_name offset_name = cls._do_name(buf, rr_offset, 0, error) if offset_name is None: e = ("do_rr", rr_offset, '_do_name failed') error.append(e) return None rr_offset, rr['MaintainerName'] = offset_name fmt = '!IIIII' fmtsz = struct.calcsize(fmt) dat = buf[rr_offset:rr_offset + fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rr_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['Serial'], rr['Refresh'], rr['Retry'], rr['Expire'], rr['NegativeTtl'] = struct.unpack(fmt, dat) elif rr['Type'] == 'SRV': fmt = '!HHH' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None (rr['Priority'], rr['Weight'], rr['Port']) = struct.unpack(fmt, dat) rr_offset, rr['Target'] = cls._do_name(buf, rdata_offset+fmtsz, 0, error) elif rr['Type'] == 'SSHFP': fmt = '!BB' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None (rr['Algorithm'], rr['DigestType']) = struct.unpack(fmt, dat) rr['Fingerprint'] = cls._bytes_as_hex_str(rdata[fmtsz:]) elif rr['Type'] == 'TLSA': fmt = '!BBB' fmtsz = struct.calcsize(fmt) dat = rdata[:fmtsz] if len(dat) != fmtsz: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None rr['CertUsage'], rr['Selector'], rr['MatchingType']= \ struct.unpack(fmt, dat) rr['CertAssData'] = cls._bytes_as_hex_str(rdata[fmtsz:]) if rr['Type'] == 'TXT': if rr['Class'] == "IN" or rr['Class'] == "CH": fmt = "!B" reqlen = struct.calcsize(fmt) o = 0 rr['Data'] = [] while o < len(rdata): strng = rdata[o:o+reqlen] if len(strng) != reqlen: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None res = struct.unpack(fmt, strng) llen = res[0] o += reqlen strng = rdata[o:o+llen] if len(strng) < llen: e = ("_do_rr", rdata_offset, 'offset out of range: rdata size = %d' % len(rdata)) error.append(e) return None strng = cls._clean_up_string(strng) rr['Data'].append(strng) o += llen if isinstance(rr["Class"], int) or isinstance(rr["Type"], int): # Unknown class or type. Just add a RDATA field with hex data rr['Rdata'] = cls._bytes_as_hex_str(rdata) return offset, rr @classmethod def _do_name(cls, buf, offset, recurs, error): if recurs >= 256: e = ("_do_name", offset, 'too much recursion') error.append(e) return None name = '' while True: fmt = "!B" reqlen = struct.calcsize(fmt) strng = buf[offset:offset + reqlen] if len(strng) != reqlen: e = ("_do_name", offset, 'offset out of range: buf size = %d' % len(buf)) error.append(e) return None res = struct.unpack(fmt, strng) llen = res[0] if llen <= 63: # Label offset += 1 label = buf[offset:offset + llen] offset = offset + llen label_as_str = cls._clean_up_string(label) if name == '' or label_as_str != '': name = name + label_as_str + '.' if llen == 0: break elif llen >= 0xC0: fmt = "!H" reqlen = struct.calcsize(fmt) strng = buf[offset:offset + reqlen] if len(strng) != reqlen: e = ("_do_name", offset, 'offset out of range: buf size = %d' % len(buf)) error.append(e) return None res = struct.unpack(fmt, strng) poffset = res[0] & ~0xC000 n = cls._do_name(buf, poffset, recurs+1, error) if n is None: e = ("_do_name", poffset, 'bad offset %d at offset %d' % (poffset, offset)) error.append(e) return None poffset, pname = n offset += reqlen name = name + pname break else: e = ("_do_name", offset, 'bad len 0x%x' % llen) error.append(e) return None return offset, name __all__ = ( "DnsResult", ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/helpers/compatibility.py000066400000000000000000000015041405365472700247020ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ We put stuff here to help cope with differences between Python versions. """ try: string = basestring # Python2 except NameError: string = str # Python3 ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/http.py000066400000000000000000000066521405365472700213570ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from .base import Result, ParsingDict class Response(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.af = self.ensure("af", int) self.body_size = self.ensure("bsize", int) self.head_size = self.ensure("hsize", int) self.destination_address = self.ensure("dst_addr", str) self.source_address = self.ensure("src_addr", str) self.code = self.ensure("res", int) self.response_time = self.ensure("rt", float) self.version = self.ensure("ver", str) if not self.destination_address: self.destination_address = self.ensure( "addr", str, self.destination_address) if not self.source_address: self.source_address = self.ensure( "srcaddr", str, self.source_address) if not self.code: self._handle_malformation("No response code available") error = self.ensure("err", str) if error: self._handle_error(error) class HttpResult(Result): METHOD_GET = "GET" METHOD_POST = "POST" METHOD_PUT = "PUT" METHOD_DELETE = "DELETE" METHOD_HEAD = "HEAD" METHODS = { METHOD_GET: "GET", METHOD_POST: "POST", METHOD_PUT: "PUT", METHOD_DELETE: "DELETE", METHOD_HEAD: "HEAD" } def __init__(self, data, **kwargs): Result.__init__(self, data, **kwargs) self.uri = self.ensure("uri", str) self.method = None self.responses = [] if "result" not in self.raw_data: self._handle_malformation("No result value found") return if isinstance(self.raw_data["result"], list): # All modern results for response in self.raw_data["result"]: self.responses.append(Response(response, **kwargs)) if self.responses: method = self.raw_data["result"][0].get( "method", self.raw_data["result"][0].get("mode") # Firmware == 4300 ) if method: method = method.replace("4", "").replace("6", "") if method in self.METHODS.keys(): self.method = self.METHODS[method] else: # Firmware <= 1 response = self.raw_data["result"].split(" ") self.method = response[0].replace("4", "").replace("6", "") self.responses.append(Response({ "dst_addr": response[1], "rt": float(response[2]) * 1000, "res": int(response[3]), "hsize": int(response[4]), "bsize": int(response[5]), })) __all__ = ( "HttpResult" ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/ntp.py000066400000000000000000000122271405365472700211740ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from datetime import datetime from dateutil.relativedelta import relativedelta from pytz import UTC from .base import Result, ResultParseError, ParsingDict class Packet(ParsingDict): """ Model for data structure of each packet for a NTP result. """ NTP_EPOCH = datetime(1900, 1, 1, tzinfo=UTC) def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.rtt = None self.offset = None if "rtt" not in data: return try: self.rtt = round(float(data["rtt"]), 3) except (ValueError, TypeError): raise ResultParseError( 'RTT "{rtt}" does not appear to be a float'.format( rtt=data["rtt"]) ) self.offset = self.ensure("offset", float) self.final_timestamp = self.ensure("final-ts", float) self.origin_timestamp = self.ensure("origin-ts", float) self.received_timestamp = self.ensure("receive-ts", float) self.transmitted_timestamp = self.ensure("transmit-ts", float) # Caching self._final_time = None self._origin_time = None self._received_time = None self._transmitted_time = None def __str__(self): return "{rtt}|{offset}".format(rtt=self.rtt, offset=self.offset) @property def final_time(self): if not self._final_time and self.final_timestamp: self._final_time = self.NTP_EPOCH + relativedelta( seconds=self.final_timestamp) return self._final_time @property def origin_time(self): if not self._origin_time and self.origin_timestamp: self._origin_time = self.NTP_EPOCH + relativedelta( seconds=self.origin_timestamp) return self._origin_time @property def received_time(self): if not self._received_time and self.received_timestamp: self._received_time = self.NTP_EPOCH + relativedelta( seconds=self.received_timestamp) return self._received_time @property def transmitted_time(self): if not self._transmitted_time and self.transmitted_timestamp: self._transmitted_time = self.NTP_EPOCH + relativedelta( seconds=self.transmitted_timestamp) return self._transmitted_time class NtpResult(Result): """ Subclass to cover ntp type measurement results. """ def __init__(self, data, **kwargs): Result.__init__(self, data, **kwargs) self.rtt_median = None self.rtt_min = None self.rtt_max = None self.offset_median = None self.offset_min = None self.offset_max = None self.af = self.ensure("af", int) self.protocol = self.ensure("proto", str) self.destination_address = self.ensure("dst_addr", str) self.destination_name = self.ensure("dst_name", str) self.source_address = self.ensure("src_addr", str) self.end_time = self.ensure("endtime", "datetime") self.leap_second_indicator = self.ensure("li", str) self.mode = self.ensure("mode", str) self.poll = self.ensure("poll", int) self.precision = self.ensure("precision", float) self.reference_id = self.ensure("ref-id", str) self.reference_time = self.ensure("ref-ts", float) self.root_delay = self.ensure("root-delay", int) self.root_dispersion = self.ensure("root-dispersion", float) self.stratum = self.ensure("stratum", int) self.version = self.ensure("version", int) self.packets = [] if "result" not in self.raw_data: self._handle_malformation("No result value found") return for response in self.raw_data["result"]: self.packets.append(Packet(response, **kwargs)) self._set_medians_and_extremes() def _set_medians_and_extremes(self): """ Sets median values for rtt and the offset of result packets. """ rtts = sorted([p.rtt for p in self.packets if p.rtt is not None]) if rtts: self.rtt_min = rtts[0] self.rtt_max = rtts[-1] self.rtt_median = self.calculate_median(rtts) offsets = sorted( [p.offset for p in self.packets if p.offset is not None] ) if offsets: self.offset_min = offsets[0] self.offset_max = offsets[-1] self.offset_median = self.calculate_median(offsets) __all__ = ( "NtpResult" ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/ping.py000066400000000000000000000104511405365472700213250ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from .base import Result, ResultParseError, ParsingDict class Packet(ParsingDict): def __init__(self, data, default_ttl, default_source_address, **kwargs): ParsingDict.__init__(self, **kwargs) self.rtt = None self.dup = False self.ttl = None self.source_address = data.get( "src_addr", data.get( "srcaddr", default_source_address ) ) if "rtt" in data: try: self.rtt = round(float(data["rtt"]), 3) except (ValueError, TypeError): raise ResultParseError( 'RTT "{rtt}" does not appear to be a float'.format( rtt=data["rtt"] ) ) if self.rtt: self.ttl = default_ttl if "ttl" in data: try: self.ttl = int(data["ttl"]) except (ValueError, TypeError): raise ResultParseError( 'TTL "{ttl}" does not appear to be an integer'.format( ttl=data["ttl"] ) ) if "dup" in data: self.dup = True def __str__(self): return str(self.rtt) class PingResult(Result): """ Ping measurement result class """ def __init__(self, data, **kwargs): Result.__init__(self, data, **kwargs) self.af = self.ensure("af", int) self.duplicates = self.ensure("dup", int) self.rtt_average = self.ensure("avg", float) self.rtt_max = self.ensure("max", float) self.rtt_min = self.ensure("min", float) self.packets_sent = self.ensure("sent", int) self.packets_received = self.ensure("rcvd", int) self.packet_size = self.ensure("size", int) self.destination_name = self.ensure("dst_name", str) self.destination_address = self.ensure("dst_addr", str) self.step = self.ensure("step", int) self.rtt_median = None # Redefined in self._set_rtt_median() self.packets = [] if self.rtt_average is None or self.rtt_average < 0: self.rtt_average = self.rtt_min = self.rtt_max = None if 0 < self.firmware < 4460: self.af = self.ensure("pf", int) self.protocol = self.clean_protocol(self.ensure("proto", str)) if 0 < self.firmware < 4460: self.destination_address = self.ensure("addr", str) self.destination_name = self.ensure("name", str) self.packet_size = None elif 0 < self.firmware < 4570 and self.protocol == self.PROTOCOL_ICMP: self.packet_size -= 8 if self.af is None and self.destination_address: self.af = 4 if ":" in self.destination_address: self.af = 6 if self.rtt_average: self.rtt_average = round(self.rtt_average, 3) self._parse_packets(**kwargs) self._set_rtt_median() def _parse_packets(self, **kwargs): source_address = self.raw_data.get( "src_addr", self.raw_data.get("srcaddr") ) for packet in self.ensure("result", list, []): self.packets.append( Packet( packet, self.ensure("ttl", int), source_address, **kwargs ) ) def _set_rtt_median(self): packets = sorted([ p.rtt for p in self.packets if p.rtt is not None and p.dup is False ]) self.rtt_median = self.calculate_median(packets) __all__ = ( "PingResult", ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/ssl.py000066400000000000000000000211501405365472700211670ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import logging import pytz import codecs from datetime import datetime try: from cryptography import x509 from cryptography.x509.oid import NameOID from cryptography.hazmat.backends import openssl from cryptography.hazmat.primitives import hashes except ImportError: logging.warning( "cryptography module is not installed, without it you cannot parse SSL " "certificate measurement results" ) from .base import Result, ParsingDict from .helpers.compatibility import string EXT_SAN = "subjectAltName" class Certificate(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.subject_cn = None self.subject_o = None self.subject_c = None self.issuer_cn = None self.issuer_o = None self.issuer_c = None self.valid_from = None self.valid_until = None self.checksum_md5 = None self.checksum_sha1 = None self.checksum_sha256 = None self.has_expired = None self.extensions = {} cert = x509.load_pem_x509_certificate(data.encode("ascii"), openssl.backend) if cert: self.checksum_md5 = self._colonify(cert.fingerprint(hashes.MD5())) self.checksum_sha1 = self._colonify(cert.fingerprint(hashes.SHA1())) self.checksum_sha256 = self._colonify(cert.fingerprint(hashes.SHA256())) self.valid_from = pytz.utc.localize(cert.not_valid_before) self.valid_until = pytz.utc.localize(cert.not_valid_after) self.has_expired = self._has_expired() self._add_extensions(cert) if cert and cert.subject: self.subject_cn, self.subject_o, self.subject_c = \ self._parse_x509_name(cert.subject) if cert and cert.issuer: self.issuer_cn, self.issuer_o, self.issuer_c = \ self._parse_x509_name(cert.issuer) # OID name lookup of the common abbreviations # In reality probably only CN will be used _oid_names = { NameOID.COMMON_NAME: "CN", NameOID.ORGANIZATION_NAME: "O", NameOID.ORGANIZATIONAL_UNIT_NAME: "OU", NameOID.COUNTRY_NAME: "C", NameOID.STATE_OR_PROVINCE_NAME: "S", NameOID.LOCALITY_NAME: "L", } def _get_oid_name(self, oid): return self._oid_names.get(oid, oid.dotted_string) def _name_attribute_to_string(self, name): """ Build a /-separated string from an x509.Name. """ return "".join( "/{}={}".format( self._get_oid_name(attr.oid), attr.value, ) for attr in name ) def _get_subject_alternative_names(self, ext): """ Return a list of Subject Alternative Name values for the given x509 extension object. """ values = [] for san in ext.value: if isinstance(san.value, string): # Pass on simple string SAN values values.append(san.value) elif isinstance(san.value, x509.Name): # In theory there there could be >1 RDN here... values.extend( self._name_attribute_to_string(rdn) for rdn in san.value.rdns ) return values def _add_extensions(self, cert): for ext in cert.extensions: if ext.oid._name == EXT_SAN: self.extensions[EXT_SAN] = self._get_subject_alternative_names(ext) @staticmethod def _colonify(bytes): hex = codecs.getencoder("hex_codec")(bytes)[0].decode("ascii").upper() return ":".join(a+b for a, b in zip(hex[::2], hex[1::2])) @staticmethod def _parse_x509_name(name): cn = None o = None c = None for attr in name: if attr.oid == NameOID.COUNTRY_NAME: c = attr.value elif attr.oid == NameOID.ORGANIZATION_NAME: o = attr.value elif attr.oid == NameOID.COMMON_NAME: cn = attr.value return cn, o, c def _has_expired(self): now = pytz.utc.localize(datetime.utcnow()) return self.valid_from <= now <= self.valid_until @property def cn(self): return self.subject_cn @property def o(self): return self.subject_o @property def c(self): return self.subject_c @property def common_name(self): return self.cn @property def organisation(self): return self.o @property def country(self): return self.c @property def checksum(self): return self.checksum_sha256 class Alert(ParsingDict): # Taken from https://tools.ietf.org/html/rfc5246#section-7.2 DESCRIPTION_MAP = { 0: "close_notify", 10: "unexpected_message", 20: "bad_record_mac", 21: "decryption_failed_RESERVED", 22: "record_overflow", 30: "decompression_failure", 40: "handshake_failure", 41: "no_certificate_RESERVED", 42: "bad_certificate", 43: "unsupported_certificate", 44: "certificate_revoked", 45: "certificate_expired", 46: "certificate_unknown", 47: "illegal_parameter", 48: "unknown_ca", 49: "access_denied", 50: "decode_error", 51: "decrypt_error", 60: "export_restriction_RESERVED", 70: "protocol_version", 71: "insufficient_security", 80: "internal_error", 90: "user_canceled", 100: "no_renegotiation", 110: "unsupported_extension", } def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.level = self.ensure("level", int) self.description = self.ensure("decription", int) if self.description is None: self.description = self.ensure("description", int) @property def description_string(self): return self.DESCRIPTION_MAP.get(self.description, "Unknown") class SslResult(Result): def __init__(self, data, **kwargs): Result.__init__(self, data, **kwargs) self.af = self.ensure("af", int) self.destination_address = self.ensure("dst_addr", str) self.destination_name = self.ensure("dst_name", str) self.source_address = self.ensure("src_addr", str) self.port = self.ensure("dst_port", int) self.method = self.ensure("method", str) self.version = self.ensure("ver", str) self.response_time = self.ensure("rt", float) self.time_to_connect = self.ensure("ttc", float) if "error" in self.raw_data: self._handle_error(self.raw_data["error"]) # Older versions used named ports if self.port is None and self.raw_data.get("dst_port") == "https": self.port = 443 self.alert = None self.certificates = [] self.is_self_signed = False if "alert" in self.raw_data: self.alert = Alert(self.raw_data["alert"], **kwargs) self._handle_error(self.alert.description_string) if "cert" in self.raw_data and isinstance(self.raw_data["cert"], list): for certificate in self.raw_data["cert"]: try: self.certificates.append(Certificate(certificate, **kwargs)) except Exception as exc: self._handle_error(str(exc)) continue if len(self.certificates) == 1: certificate = self.certificates[0] if certificate.subject_cn == certificate.issuer_cn: self.is_self_signed = True @property def checksum_chain(self): """ Returns a list of checksums joined with "::". """ checksums = [] for certificate in self.certificates: checksums.append(certificate.checksum) return "::".join(checksums) __all__ = ( "SslResult" ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/traceroute.py000066400000000000000000000176611405365472700225570ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import logging from calendar import timegm from .base import Result, ParsingDict class IcmpHeader(ParsingDict): """ But why did we stop here? Why not go all the way and define subclasses for each object and for `mpls`? it comes down to a question of complexity vs. usefulness. This is such a fringe case that it's probably fine to just dump the data in to `self.objects` and let people work from there. If however you feel that this needs expansion, pull requests are welcome :-) Further information regarding the structure and meaning of the data in this class can be found here: http://localhost:8000/docs/data_struct/ """ def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.version = self.ensure("version", int) self.rfc4884 = self.ensure("rfc4884", bool) self.objects = self.ensure("obj", list) class Packet(ParsingDict): ERROR_CONDITIONS = { "N": "Network unreachable", "H": "Destination unreachable", "A": "Administratively prohibited", "P": "Protocol unreachable", "p": "Port unreachable", } def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.origin = self.ensure("from", str) self.rtt = self.ensure("rtt", float) self.size = self.ensure("size", int) self.ttl = self.ensure("ttl", int) self.mtu = self.ensure("mtu", int) self.destination_option_size = self.ensure("dstoptsize", int) self.hop_by_hop_option_size = self.ensure("hbhoptsize", int) self.arrived_late_by = self.ensure("late", int, 0) self.internal_ttl = self.ensure("ittl", int, 1) if self.rtt: self.rtt = round(self.rtt, 3) error = self.ensure("err", str) if error: self._handle_error(self.ERROR_CONDITIONS.get(error, error)) icmp_header = self.ensure("icmpext", dict) self.icmp_header = None if icmp_header: self.icmp_header = IcmpHeader(icmp_header, **kwargs) def __str__(self): return self.origin class Hop(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.raw_data = data self.index = self.ensure("hop", int) error = self.ensure("error", str) if error: self._handle_error(error) self.packets = [] packet_rtts = [] if "result" in self.raw_data: for raw_packet in self.raw_data["result"]: if "late" not in raw_packet: packet = Packet(raw_packet, **kwargs) if packet.rtt: packet_rtts.append(packet.rtt) self.packets.append(packet) self.median_rtt = Result.calculate_median(packet_rtts) def __str__(self): return str(self.index) class TracerouteResult(Result): def __init__(self, data, **kwargs): Result.__init__(self, data, **kwargs) self.af = self.ensure("af", int) self.destination_address = self.ensure("dst_addr", str) self.destination_name = self.ensure("dst_name", str) self.source_address = self.ensure("src_addr", str) self.end_time = self.ensure("endtime", "datetime") self.paris_id = self.ensure("paris_id", int) self.size = self.ensure("size", int) if 0 < self.firmware < 4460: self.af = self.ensure("pf", int) self.protocol = self.clean_protocol(self.ensure("proto", str)) self.hops = [] self.total_hops = 0 self.last_median_rtt = None # Used by a few response tests below self.destination_ip_responded = False self.last_hop_responded = False self.is_success = False self.last_hop_errors = [] self._parse_hops(**kwargs) # Sets hops, last_median_rtt, and total_hops @property def last_rtt(self): logging.warning( '"last_rtt" is deprecated and will be removed in future versions. ' 'Instead, use "last_median_rtt".') return self.last_median_rtt @property def target_responded(self): logging.warning( 'The "target_responded" property is deprecated and will be removed ' 'in future versions. Instead, use "destination_ip_responded".' ) return self.destination_ip_responded def set_destination_ip_responded(self, last_hop): """Sets the flag if destination IP responded.""" if not self.destination_address: return for packet in last_hop.packets: if packet.origin and \ self.destination_address == packet.origin: self.destination_ip_responded = True break def set_last_hop_responded(self, last_hop): """Sets the flag if last hop responded.""" for packet in last_hop.packets: if packet.rtt: self.last_hop_responded = True break def set_is_success(self, last_hop): """Sets the flag if traceroute result is successful or not.""" for packet in last_hop.packets: if packet.rtt and not packet.is_error: self.is_success = True break else: self.set_last_hop_errors(last_hop) def set_last_hop_errors(self, last_hop): """Sets the last hop's errors.""" if last_hop.is_error: self.last_hop_errors.append(last_hop.error_message) return for packet in last_hop.packets: if packet.is_error: self.last_hop_errors.append(packet.error_message) @property def end_time_timestamp(self): return timegm(self.end_time.timetuple()) @property def ip_path(self): """ Returns just the IPs from the traceroute. """ r = [] for hop in self.hops: r.append([packet.origin for packet in hop.packets]) return r def _parse_hops(self, parse_all_hops=True, **kwargs): try: hops = self.raw_data["result"] assert(isinstance(hops, list)) except (KeyError, AssertionError): self._handle_malformation("Legacy formats not supported") return num_hops = len(hops) # Go through the hops in reverse so that if # parse_all_hops is False we can stop processing as # soon as possible. for index, raw_hop in reversed(list(enumerate(hops))): hop = Hop(raw_hop, **kwargs) # If last hop set several useful attributes if index + 1 == num_hops: self.set_destination_ip_responded(hop) self.set_last_hop_responded(hop) self.set_is_success(hop) # We always store the last hop self.hops.insert(0, hop) elif parse_all_hops: self.hops.insert(0, hop) if hop.median_rtt and not self.last_median_rtt: self.last_median_rtt = hop.median_rtt if not parse_all_hops: # Now that we have the last RTT we can stop break self.total_hops = num_hops __all__ = ( "TracerouteResult", ) ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/version.py000066400000000000000000000012611405365472700220540ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . __version__ = "1.3.1" ripe-atlas-sagan-1.3.1/ripe/atlas/sagan/wifi.py000066400000000000000000000031551405365472700213310ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from .base import Result, ParsingDict class WPASupplicant(ParsingDict): def __init__(self, data, **kwargs): ParsingDict.__init__(self, **kwargs) self.address = data.get("address") self.bssid = data.get("bssid") self.connect_time = data.get("connect-time") self.group_cipher = data.get("group_cipher") self.wpa_supplicant_id = data.get("id") self.ip_address = data.get("ip_address") self.key_management = data.get("key_mgmt") self.mode = data.get("mode") self.pairwise_cipher = data.get("pairwise_cipher") self.ssid = data.get("ssid") self.wpa_state = data.get("wpa_state") class WiFiResult(Result): """ WiFi measurement result class """ def __init__(self, data, **kwargs): Result.__init__(self, data, **kwargs) self.wpa_supplicant = WPASupplicant( data["wpa_supplicant"], **kwargs ) __all__ = ( "WiFiResult", ) ripe-atlas-sagan-1.3.1/setup.cfg000066400000000000000000000000261405365472700165000ustar00rootroot00000000000000[wheel] universal = 1 ripe-atlas-sagan-1.3.1/setup.py000066400000000000000000000042501405365472700163740ustar00rootroot00000000000000import os from setuptools import setup __version__ = None exec(open("ripe/atlas/sagan/version.py").read()) name = "ripe.atlas.sagan" install_requires = [ "python-dateutil", "pytz", ] tests_require = ["nose"] if "SAGAN_WITHOUT_SSL" not in os.environ: install_requires.append("cryptography") # Allow setup.py to be run from any path os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) readme_path = os.path.join(os.path.dirname(__file__), "README.rst") changelog_path = os.path.join(os.path.dirname(__file__), "CHANGES.rst") # Get the long description from README.md with open(readme_path) as readme: with open(changelog_path) as changelog: setup( name="ripe.atlas.sagan", version=__version__, packages=["ripe", "ripe.atlas", "ripe.atlas.sagan"], namespace_packages=["ripe", "ripe.atlas"], include_package_data=True, license="GPLv3", description="A parser for RIPE Atlas measurement results", long_description="{readme}\n\n{changelog}".format( readme=readme.read(), changelog=changelog.read() ), url="https://github.com/RIPE-NCC/ripe.atlas.sagan", download_url="https://github.com/RIPE-NCC/ripe.atlas.sagan", author="The RIPE Atlas Team", author_email="atlas@ripe.net", maintainer="The RIPE Atlas Team", maintainer_email="atlas@ripe.net", install_requires=install_requires, tests_require=tests_require, extras_require={ "fast": ["ujson"], "doc": ["sphinx"] }, test_suite="nose.collector", classifiers=[ "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP", ], ) ripe-atlas-sagan-1.3.1/tests/000077500000000000000000000000001405365472700160235ustar00rootroot00000000000000ripe-atlas-sagan-1.3.1/tests/__init__.py000066400000000000000000000014521405365472700201360ustar00rootroot00000000000000# Copyright (c) 2015 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from .ping import * from .traceroute import * from .dns import * from .ssl import * from .http import * from .ntp import * from .wifi import * ripe-atlas-sagan-1.3.1/tests/dns.py000066400000000000000000002537371405365472700172020ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from collections import namedtuple from ripe.atlas.sagan import Result, ResultError from ripe.atlas.sagan.dns import ( DnsResult, Edns0, Answer, AAnswer, AaaaAnswer, NsAnswer, CnameAnswer, MxAnswer, SoaAnswer, DsAnswer, DnskeyAnswer, RRSigAnswer, NsecAnswer, Nsec3Answer, Nsec3ParamAnswer, PtrAnswer, SrvAnswer, SshfpAnswer, TxtAnswer, HinfoAnswer, TlsaAnswer ) def test_dns_4460(): result = Result.get('{"af":4,"dst_addr":"193.227.234.53","from":"217.172.81.146","fw":4460,"msm_id":1004041,"prb_id":184,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":39825,"NSCOUNT":0,"QDCOUNT":1,"abuf":"m5GEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==","answers":[{"RDLENGTH":4,"TYPE":1}],"rt":45.305,"size":43},"timestamp":1347765990,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin == "217.172.81.146") assert(result.firmware == 4460) assert(result.measurement_id == 1004041) assert(result.probe_id == 184) assert(result.created.isoformat() == "2012-09-16T03:26:30+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "193.227.234.53") assert(result.responses[0].source_address is None) assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "m5GEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==") assert(result.responses[0].response_time == 45.305) assert(result.responses[0].response_size == 43) assert(result.responses[0].abuf.header.aa is True) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 0) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is False) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 0) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is False) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 39825) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "as250.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "as250.net.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].address == "194.150.168.100") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) def test_dns_4470(): result = Result.get('{"af":4,"dst_addr":"193.227.234.53","from":"195.47.235.67","fw":4470,"msm_id":1004041,"prb_id":148,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":63020,"NSCOUNT":0,"QDCOUNT":1,"abuf":"9iyEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==","rt":30.733000000000001,"size":43},"src_addr":"195.47.235.67","timestamp":1352273196,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin == "195.47.235.67") assert(result.firmware == 4470) assert(result.measurement_id == 1004041) assert(result.probe_id == 148) assert(result.created.isoformat() == "2012-11-07T07:26:36+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "193.227.234.53") assert(result.responses[0].source_address == "195.47.235.67") assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "9iyEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==") assert(result.responses[0].response_time == 30.733) assert(result.responses[0].response_size == 43) assert(result.responses[0].abuf.header.aa is True) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 0) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is False) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 0) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is False) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 63020) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "as250.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "as250.net.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].address == "194.150.168.100") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) def test_dns_4480(): result = Result.get('{"af":4,"dst_addr":"193.227.234.53","from":"46.17.16.18","fw":4480,"msm_id":1004041,"prb_id":778,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":12288,"NSCOUNT":0,"QDCOUNT":1,"abuf":"MACEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==","rt":38.576999999999998,"size":43},"src_addr":"192.168.1.12","timestamp":1363332374,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin == "46.17.16.18") assert(result.firmware == 4480) assert(result.measurement_id == 1004041) assert(result.probe_id == 778) assert(result.created.isoformat() == "2013-03-15T07:26:14+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "193.227.234.53") assert(result.responses[0].source_address == "192.168.1.12") assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "MACEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==") assert(result.responses[0].response_time == 38.577) assert(result.responses[0].response_size == 43) assert(result.responses[0].abuf.header.aa is True) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 0) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is False) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 0) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is False) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 12288) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "as250.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "as250.net.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].address == "194.150.168.100") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) def test_dns_4500(): result = Result.get('{"af":4,"dst_addr":"193.227.234.53","from":"176.28.80.97","fw":4500,"msm_id":1004041,"prb_id":2918,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":57235,"NSCOUNT":0,"QDCOUNT":1,"abuf":"35OEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==","rt":69.736999999999995,"size":43},"src_addr":"10.220.3.215","timestamp":1366255550,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin == "176.28.80.97") assert(result.firmware == 4500) assert(result.measurement_id == 1004041) assert(result.probe_id == 2918) assert(result.created.isoformat() == "2013-04-18T03:25:50+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "193.227.234.53") assert(result.responses[0].source_address == "10.220.3.215") assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "35OEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaoZA==") assert(result.responses[0].response_time == 69.737) assert(result.responses[0].response_size == 43) assert(result.responses[0].abuf.header.aa is True) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 0) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is False) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 0) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is False) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 57235) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "as250.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "as250.net.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].address == "194.150.168.100") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) def test_dns_4520(): result = Result.get('{"af":4,"dst_addr":"193.227.234.53","fw":4520,"msm_id":1004041,"prb_id":203,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":1472,"NSCOUNT":0,"QDCOUNT":1,"abuf":"BcCEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaooA==","rt":362.416,"size":43},"src_addr":"118.208.45.191","timestamp":1373241512,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin is None) assert(result.firmware == 4520) assert(result.measurement_id == 1004041) assert(result.probe_id == 203) assert(result.created.isoformat() == "2013-07-07T23:58:32+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "193.227.234.53") assert(result.responses[0].source_address == "118.208.45.191") assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "BcCEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaooA==") assert(result.responses[0].response_time == 362.416) assert(result.responses[0].response_size == 43) assert(result.responses[0].abuf.header.aa is True) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 0) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is False) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 0) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is False) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 1472) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "as250.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "as250.net.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].address == "194.150.168.160") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) def test_dns_4610(): result = Result.get('{"af":4,"dst_addr":"193.227.234.53","from":"79.134.181.58","fw":4610,"msm_id":1004041,"msm_name":"Tdig","prb_id":714,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":15824,"NSCOUNT":0,"QDCOUNT":1,"abuf":"PdCEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaooA==","rt":81.718000000000004,"size":43},"result-rt":81.718000000000004,"src_addr":"192.168.0.100","timestamp":1395856407,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin == "79.134.181.58") assert(result.firmware == 4610) assert(result.measurement_id == 1004041) assert(result.probe_id == 714) assert(result.created.isoformat() == "2014-03-26T17:53:27+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "193.227.234.53") assert(result.responses[0].source_address == "192.168.0.100") assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "PdCEAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaooA==") assert(result.responses[0].response_time == 81.718) assert(result.responses[0].response_size == 43) assert(result.responses[0].abuf.header.aa is True) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 0) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is False) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 0) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is False) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 15824) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "as250.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "as250.net.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].address == "194.150.168.160") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) def test_resultset(): result = Result.get('{"from":"87.218.115.95","fw":4610,"msm_id":1004049,"msm_name":"Tdig","prb_id":13337,"resultset":[{"af":4,"dst_addr":"192.168.1.1","proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":6,"ID":19506,"NSCOUNT":6,"QDCOUNT":1,"abuf":"TDKBgAABAAEABgAGA3d3dwRyaXBlA25ldAAAAQABwAwAAQABAAAnsgAEwQAGi8AQAAIAAQAACTsADANuczMDbmljAmZyAMAQAAIAAQAACTsAEAZzbnMtcGIDaXNjA29yZwDAEAACAAEAAAk7AA0Ec2VjMQVhcG5pY8AVwBAAAgABAAAJOwAOA3ByaQdhdXRoZG5zwBDAEAACAAEAAAk7AA4GdGlubmllBGFyaW7AFcAQAAIAAQAACTsABwRzZWMzwHPAOgABAAEAASqyAATAhgAxwFIAAQABAAAZUgAEwAUEAcBuAAEAAQAAAW0ABMoMHTvAhwABAAEAAAk7AATBAAkFwKEAAQABAAAWlAAEx9QANcC7AAEAAQAACjcABMoMHIw=","rt":2.9939999999999998,"size":290},"src_addr":"192.168.1.2","subid":1,"submax":3,"time":1395792203},{"af":4,"dst_addr":"109.69.8.34","proto":"UDP","result":{"ANCOUNT":2,"ARCOUNT":15,"ID":25432,"NSCOUNT":7,"QDCOUNT":1,"abuf":"Y1iBgAABAAIABwAPA3d3dwRyaXBlA25ldAAAAQABwAwAAQABAAAnsAAEwQAGi8AMAC4AAQAAJ7AAnAABBQMAAFRgU1kk1VMxicVypgRyaXBlA25ldAAO4dloUjFkGWQKhb7ovCvAUn0NxHnxhCG/8PxtVf2+gUCxU1DAwP6mhazefe/B7Ecz5EVaF0WpbNUwhYOlEApMVgxd26DzrH7n99Yx8XN+mp/jts7MhoXrybZyh4NJ4Lwd/eAxCwp81ZAj7YDUX+EVtM+8c5h72C1XVfYb3Q/k98BMAAIAAQAACToADQRzZWMxBWFwbmljwFHATAACAAEAAAk6ABAGc25zLXBiA2lzYwNvcmcAwEwAAgABAAAJOgAOA3ByaQdhdXRoZG5zwEzATAACAAEAAAk6AAwDbnMzA25pYwJmcgD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AAAA","rt":76.292000000000002,"size":1137},"src_addr":"192.168.1.2","subid":2,"submax":3,"time":1395792204},{"af":4,"dst_addr":"8.8.8.8","proto":"UDP","result":{"ANCOUNT":2,"ARCOUNT":1,"ID":34160,"NSCOUNT":0,"QDCOUNT":1,"abuf":"hXCBoAABAAIAAAABA3d3dwRyaXBlA25ldAAAAQABwAwAAQABAAAs2AAEwQAGi8AMAC4AAQAALNgAnAABBQMAAFRgU1kk1VMxicVypgRyaXBlA25ldAAO4dloUjFkGWQKhb7ovCvAUn0NxHnxhCG/8PxtVf2+gUCxU1DAwP6mhazefe/B7Ecz5EVaF0WpbNUwhYOlEApMVgxd26DzrH7n99Yx8XN+mp/jts7MhoXrybZyh4NJ4Lwd/eAxCwp81ZAj7YDUX+EVtM+8c5h72C1XVfYb3Q/k9wAAKQIAAACAAAAA","rt":79.971000000000004,"size":225},"src_addr":"192.168.1.2","subid":3,"submax":3,"time":1395792205}],"timestamp":1395792203,"type":"dns"}') assert(isinstance(result, DnsResult)) assert(result.origin == "87.218.115.95") assert(result.firmware == 4610) assert(result.measurement_id == 1004049) assert(result.probe_id == 13337) assert(result.created.isoformat() == "2014-03-26T00:03:23+00:00") assert(isinstance(result.responses, list)) assert(len(result.responses) == 3) assert(result.responses[0].af == 4) assert(result.responses[0].destination_address == "192.168.1.1") assert(result.responses[0].source_address == "192.168.1.2") assert(result.responses[0].protocol == DnsResult.PROTOCOL_UDP) assert(str(result.responses[0].abuf) == "TDKBgAABAAEABgAGA3d3dwRyaXBlA25ldAAAAQABwAwAAQABAAAnsgAEwQAGi8AQAAIAAQAACTsADANuczMDbmljAmZyAMAQAAIAAQAACTsAEAZzbnMtcGIDaXNjA29yZwDAEAACAAEAAAk7AA0Ec2VjMQVhcG5pY8AVwBAAAgABAAAJOwAOA3ByaQdhdXRoZG5zwBDAEAACAAEAAAk7AA4GdGlubmllBGFyaW7AFcAQAAIAAQAACTsABwRzZWMzwHPAOgABAAEAASqyAATAhgAxwFIAAQABAAAZUgAEwAUEAcBuAAEAAQAAAW0ABMoMHTvAhwABAAEAAAk7AATBAAkFwKEAAQABAAAWlAAEx9QANcC7AAEAAQAACjcABMoMHIw=") assert(result.responses[0].response_time == 2.994) assert(result.responses[0].response_size == 290) assert(result.responses[0].abuf.header.aa is False) assert(result.responses[0].abuf.header.qr is True) assert(result.responses[0].abuf.header.nscount == 6) assert(result.responses[0].abuf.header.qdcount == 1) assert(result.responses[0].abuf.header.ancount == 1) assert(result.responses[0].abuf.header.tc is False) assert(result.responses[0].abuf.header.rd is True) assert(result.responses[0].abuf.header.cd is False) assert(result.responses[0].abuf.header.ad is False) assert(result.responses[0].abuf.header.arcount == 6) assert(result.responses[0].abuf.header.return_code == "NOERROR") assert(result.responses[0].abuf.header.opcode == "QUERY") assert(result.responses[0].abuf.header.ra is True) assert(result.responses[0].abuf.header.z == 0) assert(result.responses[0].abuf.header.id == 19506) assert(result.responses[1].abuf.header.id == 25432) assert(result.responses[2].abuf.header.id == 34160) assert(isinstance(result.responses[0].abuf.questions, list)) assert(result.responses[0].abuf.questions[0].klass == "IN") assert(result.responses[0].abuf.questions[0].type == "A") assert(result.responses[0].abuf.questions[0].name == "www.ripe.net.") assert(result.responses[1].abuf.questions[0].type == "A") assert(result.responses[2].abuf.questions[0].name == "www.ripe.net.") assert(isinstance(result.responses[0].abuf.answers, list)) assert(isinstance(result.responses[0].abuf.answers[0], AAnswer)) assert(result.responses[0].abuf.answers[0].name == "www.ripe.net.") assert(result.responses[0].abuf.answers[0].ttl == 10162) assert(result.responses[0].abuf.answers[0].address == "193.0.6.139") assert(result.responses[0].abuf.answers[0].type == "A") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 4) assert(result.responses[1].abuf.answers[1].rd_length == 156) assert(isinstance(result.responses[0].abuf.authorities, list)) assert(len(result.responses[0].abuf.authorities) == 6) assert(result.responses[0].abuf.authorities[0].target == "ns3.nic.fr.") assert(result.responses[0].abuf.authorities[1].target == "sns-pb.isc.org.") assert(result.responses[0].abuf.authorities[2].target == "sec1.apnic.net.") assert(result.responses[0].abuf.authorities[3].target == "pri.authdns.ripe.net.") assert(result.responses[0].abuf.authorities[4].rd_length == 14) assert(result.responses[0].abuf.authorities[5].ttl == 2363) assert(result.responses[0].abuf.authorities[5].type == "NS") assert(result.responses[0].abuf.authorities[1].rd_length == 16) assert(result.responses[0].abuf.authorities[2].ttl == 2363) assert(result.responses[0].abuf.authorities[3].target == "pri.authdns.ripe.net.") assert(isinstance(result.responses[0].abuf.additionals, list)) assert(len(result.responses[0].abuf.additionals) == 6) assert(result.responses[0].abuf.additionals[0].address == "192.134.0.49") assert(result.responses[0].abuf.additionals[1].klass == "IN") assert(result.responses[0].abuf.additionals[2].name == "sec1.apnic.net.") assert(result.responses[0].abuf.additionals[3].rd_length == 4) assert(result.responses[0].abuf.additionals[4].ttl == 5780) assert(result.responses[0].abuf.additionals[3].type == "A") def test_edns0(): result = Result.get('{"from":"2001:d98:6004:1:6666:b3ff:feb0:ec1e","msm_id":1004048,"timestamp":1398939936,"fw":4610,"proto":"UDP","af":6,"result-rdata":null,"dst_addr":"2001:7fd::1","prb_id":14184,"result":{"abuf":"ACuEAAABAAEADQAYAAAGAAEAAAYAAQABUYAAQAFhDHJvb3Qtc2VydmVycwNuZXQABW5zdGxkDHZlcmlzaWduLWdycwNjb20AeAv3NAAABwgAAAOEAAk6gAABUYAAAAIAAQAH6QAAAsAcAAACAAEAB+kAAAQBYsAeAAACAAEAB+kAAAQBY8AeAAACAAEAB+kAAAQBZMAeAAACAAEAB+kAAAQBZcAeAAACAAEAB+kAAAQBZsAeAAACAAEAB+kAAAQBZ8AeAAACAAEAB+kAAAQBaMAeAAACAAEAB+kAAAQBacAeAAACAAEAB+kAAAQBasAeAAACAAEAB+kAAAQBa8AeAAACAAEAB+kAAAQBbMAeAAACAAEAB+kAAAQBbcAewBwAAQABAAfpAAAExikABMB0AAEAAQAH6QAABMDkT8nAgwABAAEAB+kAAATAIQQMwJIAAQABAAfpAAAExwdbDcChAAEAAQAH6QAABMDL5grAsAABAAEAB+kAAATABQXxwL8AAQABAAfpAAAEwHAkBMDOAAEAAQAH6QAABIA\/AjXA3QABAAEAB+kAAATAJJQRwOwAAQABAAfpAAAEwDqAHsD7AAEAAQAH6QAABMEADoHBCgABAAEAB+kAAATHB1MqwRkAAQABAAfpAAAEygwbIcAcABwAAQAH6QAAECABBQO6PgAAAAAAAAACADDAgwAcAAEAB+kAABAgAQUAAAIAAAAAAAAAAAAMwJIAHAABAAfpAAAQIAEFAAAtAAAAAAAAAAAADcCwABwAAQAH6QAAECABBQAALwAAAAAAAAAAAA\/AzgAcAAEAB+kAABAgAQUAAAEAAAAAAACAPwI1wN0AHAABAAfpAAAQIAEH\/gAAAAAAAAAAAAAAU8DsABwAAQAH6QAAECABBQMMJwAAAAAAAAACADDA+wAcAAEAB+kAABAgAQf9AAAAAAAAAAAAAAABwQoAHAABAAfpAAAQIAEFAAADAAAAAAAAAAAAQsEZABwAAQAH6QAAECABDcMAAAAAAAAAAAAAADUAACkQAAAAAAAAGAADABRrMy5hbXMtaXguay5yaXBlLm5ldA==","rt":219.205,"NSCOUNT":13,"QDCOUNT":1,"answers":[{"RNAME":"nstld.verisign-grs.com.","NAME":".","MNAME":"a.root-servers.net.","TTL":86400,"SERIAL":2014050100,"TYPE":"SOA"}],"ID":43,"ARCOUNT":24,"ANCOUNT":1,"size":808},"type":"dns","result-rname":"nstld.verisign-grs.com.","src_addr":"2001:d98:6004:1:6666:b3ff:feb0:ec1e","result-rt":219.205,"result-serial":2014050100,"msm_name":"Tdig"}') assert(isinstance(result, DnsResult)) assert(isinstance(result.responses, list)) assert(isinstance(result.responses[0].abuf.edns0, Edns0)) assert(result.responses[0].abuf.edns0.extended_return_code == 0) assert(result.responses[0].abuf.edns0.name == ".") assert(result.responses[0].abuf.edns0.type == "OPT") assert(result.responses[0].abuf.edns0.udp_size == 4096) assert(result.responses[0].abuf.edns0.version == 0) assert(result.responses[0].abuf.edns0.z == 0) assert(isinstance(result.responses[0].abuf.edns0.options, list)) assert(len(result.responses[0].abuf.edns0.options) == 1) assert(result.responses[0].abuf.edns0.options[0].nsid == "k3.ams-ix.k.ripe.net") assert(result.responses[0].abuf.edns0.options[0].code == 3) assert(result.responses[0].abuf.edns0.options[0].length == 20) assert(result.responses[0].abuf.edns0.options[0].name == "NSID") def test_error_timeout(): broken_result = {u'from': u'84.132.219.105', u'msm_id': 1666006, u'timestamp':1400570732, u'fw': 4610, u'proto': u'UDP', u'af': 4, u'msm_name':u'Tdig', u'prb_id': 2960, u'error': {u'timeout': 5000}, u'src_addr':u'192.168.179.20', u'group_id': 1666005, u'type': u'dns', u'dst_addr':u'194.0.25.16'} result = Result.get(broken_result) assert(result.is_error is True) try: Result.get(broken_result, on_error=Result.ACTION_FAIL) assert False except ResultError as e: assert(str(e) == "Timeout: 5000") def test_qbuf_single_result(): result = Result.get('{"af":6,"dst_addr":"2001:67c:e0::5","from":"2a02:2860:3:1::a","fw":4720,"group_id":2927179,"lts":30,"msm_id":2927179,"msm_name":"Tdig","prb_id":18279,"proto":"UDP","qbuf":"CcsAAAABAAAAAAABBHJpcGUDbmV0AAAcAAEAACkCAAAAgAAAAAAAAAA=","result":{"ANCOUNT":2,"ARCOUNT":1,"ID":2507,"NSCOUNT":0,"QDCOUNT":1,"abuf":"CcuEAAABAAIAAAABBHJpcGUDbmV0AAAcAAHADAAcAAEAAAEsABAgAQZ8AugAIgAAAADBAAaLwAwALgABAAABLACcABwFAgAAASxWap83VkMEJ4yCBHJpcGUDbmV0ADyhc2zuMQhsu3nU8h2qGCjw/uQM3bzqsrfbaFfSCDH3qG3pPuYJtyzkyFpI8jsUpzYjJJoy29XPeAdqXWoSsHQAD4AhVqmg0/YBctjZuIMKPs7kI3ZWjkkpVqn9kl2OT0r+Moh+gL1W/a1uIkldil0mNCi1xp/V6bRqZfCS+bL0AAApEAAAAIAAAAA=","rt":21.768,"size":233},"src_addr":"2a02:2860:3:1::a","timestamp":1447251248,"type":"dns"}') assert(str(result.responses[0].qbuf) == "CcsAAAABAAAAAAABBHJpcGUDbmV0AAAcAAEAACkCAAAAgAAAAAAAAAA=") assert(result.responses[0].qbuf.edns0.do is True) def test_qbuf_result_set(): result = Result.get('{"from":"208.118.139.24","fw":4610,"group_id":1666151,"msm_id":1666151,"msm_name":"Tdig","prb_id":15112,"resultset":[{"af":4,"dst_addr":"8.8.8.8","proto":"TCP","qbuf":"dakBgAABAAAAAAABBTE1MTEyCjE0MDA2NjU1MjMDd3d3B3R3aXR0ZXIDY29tAAABAAEAACkCAAAAgAAABAADAAA=","result":{"ANCOUNT":0,"ARCOUNT":1,"ID":30121,"NSCOUNT":1,"QDCOUNT":1,"rt":57.764,"size":133},"src_addr":"10.0.5.101","subid":1,"submax":2,"time":1400665523},{"af":4,"dst_addr":"8.8.4.4","proto":"TCP","qbuf":"JTEBgAABAAAAAAABBTE1MTEyCjE0MDA2NjU1MjQDd3d3B3R3aXR0ZXIDY29tAAABAAEAACkCAAAAgAAABAADAAA=","result":{"ANCOUNT":0,"ARCOUNT":1,"ID":9521,"NSCOUNT":1,"QDCOUNT":1,"rt":57.263,"size":133},"src_addr":"10.0.5.101","subid":2,"submax":2,"time":1400665524}],"timestamp":1400665523,"type":"dns"}') assert(result.responses[0].abuf is None) assert(str(result.responses[0].qbuf) == "dakBgAABAAAAAAABBTE1MTEyCjE0MDA2NjU1MjMDd3d3B3R3aXR0ZXIDY29tAAABAAEAACkCAAAAgAAABAADAAA=") assert(result.responses[0].qbuf.header.aa is False) assert(result.responses[0].qbuf.header.qr is False) assert(result.responses[0].qbuf.header.nscount == 0) assert(result.responses[0].qbuf.header.qdcount == 1) assert(result.responses[0].qbuf.header.ancount == 0) assert(result.responses[0].qbuf.header.tc is False) assert(result.responses[0].qbuf.header.rd is True) assert(result.responses[0].qbuf.header.arcount == 1) assert(result.responses[0].qbuf.header.return_code == "NOERROR") assert(result.responses[0].qbuf.header.opcode == "QUERY") assert(result.responses[0].qbuf.header.ra is True) assert(result.responses[0].qbuf.header.z == 0) assert(result.responses[0].qbuf.header.id == 30121) assert(len(result.responses[0].qbuf.questions) == 1) assert(result.responses[0].qbuf.questions[0].klass == "IN") assert(result.responses[0].qbuf.questions[0].type == "A") assert(result.responses[0].qbuf.questions[0].name == "15112.1400665523.www.twitter.com.") assert(result.responses[0].qbuf.edns0.extended_return_code == 0) assert(result.responses[0].qbuf.edns0.udp_size == 512) assert(result.responses[0].qbuf.edns0.version == 0) assert(result.responses[0].qbuf.edns0.z == 0) assert(result.responses[0].qbuf.edns0.type == "OPT") assert(result.responses[0].qbuf.edns0.name == ".") assert(len(result.responses[0].qbuf.edns0.options) == 1) assert(result.responses[0].qbuf.edns0.options[0].code == 3) assert(result.responses[0].qbuf.edns0.options[0].name == "NSID") assert(result.responses[0].qbuf.edns0.options[0].nsid == "") assert(result.responses[0].qbuf.edns0.options[0].length == 0) def test_aaaaanswer(): result = Result.get('{"from":"2001:67c:2e8:11::c100:136c","msm_id":1663540,"fw":4620,"af":6,"timestamp":1403091608,"proto":"UDP","dst_addr":"2001:41d0:1:4874::1","prb_id":6012,"result":{"abuf":"1jKEAAABAAEAAgADCnBvc3RtYXN0ZXICZnIAABwAAcAMABwAAQAAASwAECABQdAAAUh0AAAAAAAAAAHADAACAAEAAAEsAAYDbnMxwAzADAACAAEAAAEsAAYDbnMywAzARwABAAEAAAEsAARXYtl0wEcAHAABAAABLAAQIAFB0AABSHQAAAAAAAAAAcBZAAEAAQAAASwABFzzEZ8=","rt":8.656,"NSCOUNT":2,"QDCOUNT":1,"ANCOUNT":1,"ARCOUNT":3,"ID":54834,"size":155},"result-rt":8.656,"src_addr":"2001:67c:2e8:11::c100:136c","group_id":1663540,"type":"dns","msm_name":"Tdig","name":"2001:41d0:1:4874:0:0:0:1"}') assert(isinstance(result.responses[0].abuf.answers[0], AaaaAnswer)) assert(result.responses[0].abuf.answers[0].address == "2001:41d0:1:4874:0:0:0:1") assert(result.responses[0].abuf.answers[0].name == "postmaster.fr.") assert(result.responses[0].abuf.answers[0].ttl == 300) assert(result.responses[0].abuf.answers[0].type == "AAAA") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 16) def test_cnameanswer(): result = Result.get('{"from":"2001:410:90ff:0:a2f3:c1ff:fec4:4a01","msm_id":1687656,"timestamp":1403101065,"fw":4610,"proto":"UDP","af":6,"msm_name":"Tdig","prb_id":13330,"result":{"abuf":"n9mEAAABAAIABgACBHR0MDEEcmlwZQNuZXQAAAEAAcAMAAUAAQAAVGAABgNudHDAEcArAAEAAQAAVGAABMEAAOXAEQACAAEAAA4QABAGc25zLXBiA2lzYwNvcmcAwBEAAgABAAAOEAAMA25zMwNuaWMCZnIAwBEAAgABAAAOEAANBHNlYzEFYXBuaWPAFsARAAIAAQAADhAADgZ0aW5uaWUEYXJpbsAWwBEAAgABAAAOEAAHBHNlYzPAhsARAAIAAQAADhAADgNwcmkHYXV0aGRuc8ARwMcAAQABAAAOEAAEwQAJBcDHABwAAQAADhAAECABBnwA4AAAAAAAAAAAAAU=","rt":84.262,"NSCOUNT":6,"QDCOUNT":1,"ID":40921,"ARCOUNT":2,"ANCOUNT":2,"size":257},"result-rt":84.262,"src_addr":"2001:410:90ff:0:a2f3:c1ff:fec4:4a01","group_id":1687656,"type":"dns","dst_addr":"2001:67c:e0::5"}') assert(isinstance(result.responses[0].abuf.answers[0], CnameAnswer)) assert(result.responses[0].abuf.answers[0].name == "tt01.ripe.net.") assert(result.responses[0].abuf.answers[0].ttl == 21600) assert(result.responses[0].abuf.answers[0].type == "CNAME") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 6) assert(result.responses[0].abuf.answers[0].target == "ntp.ripe.net.") def test_dnskeyanswer(): result = Result.get('{"af":6,"dst_addr":"2001:500:40::1","from":"2605:e000:160f:4097:6666:b3ff:feb0:cd7c","fw":4610,"group_id":1672218,"msm_id":1672220,"msm_name":"Tdig","pr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i4hVrC5lUubqTU91PjKZARCWb4t0WZ7Br8ySojMV0CZtmiIxRm8/4tS02AAApEAAAAIAAAAA=","rt":62.748,"size":1625},"result-rt":62.748,"src_addr":"2605:e000:160f:4097:6666:b3ff:feb0:cd7c","timestamp":1402768690,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], DnskeyAnswer)) assert(result.responses[0].abuf.answers[0].flags == 256) assert(result.responses[0].abuf.answers[0].algorithm == 7) assert(result.responses[0].abuf.answers[0].protocol == 3) assert(result.responses[0].abuf.answers[0].key == "AwEAAX7wnIyA9rd+WWcUxE6ILCCtZWvJ9aVgG7wiNYbbQp6tPn5gTmZxR35tV2WK0bHordMGJrlTuH3u8rqBYxOM/LWHj6OAGtsE8RQQhcJCzOGpQADJggSAoSNhoJ/qiXAT6wcwPrwmVnUFLV8Sok/kEbRKnXuSqIPfSVj+j9VodpFH") assert(result.responses[0].abuf.answers[0].name == "org.") assert(result.responses[0].abuf.answers[0].ttl == 900) assert(result.responses[0].abuf.answers[0].type == "DNSKEY") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 136) def test_dsanswer(): result = Result.get('{"from":"2607:f0b0:e:1000:6666:b3ff:fec5:21e","msm_id":1687655,"timestamp":1403100350,"fw":4610,"proto":"UDP","af":6,"msm_name":"Tdig","prb_id":17460,"result":{"abuf":"I4SEAAABAAEAAAAAB3RlY2hpbmMCbmwAACsAAcAMACsAAQAAHCAAJB+nBwJJII0cWAXwOgMwXauyVu24mdSr2nOQuqNwJtBOj\/Kqfw==","rt":99.33,"NSCOUNT":0,"QDCOUNT":1,"ID":9092,"ARCOUNT":0,"ANCOUNT":1,"size":76},"result-rt":99.33,"src_addr":"2607:f0b0:e:1000:6666:b3ff:fec5:21e","group_id":1687655,"type":"dns","dst_addr":"2001:7b8:606::85"}') assert(isinstance(result.responses[0].abuf.answers[0], DsAnswer)) assert(result.responses[0].abuf.answers[0].name == "techinc.nl.") assert(result.responses[0].abuf.answers[0].ttl == 7200) assert(result.responses[0].abuf.answers[0].type == "DS") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 36) assert(result.responses[0].abuf.answers[0].tag == 8103) assert(result.responses[0].abuf.answers[0].algorithm == 7) assert(result.responses[0].abuf.answers[0].digest_type == 2) assert(result.responses[0].abuf.answers[0].delegation_key == "49208d1c5805f03a03305dabb256edb899d4abda7390baa37026d04e8ff2aa7f") def test_hinfoanswer(): result = Result.get('{"af":4,"dst_addr":"192.31.231.42","from":"78.27.190.13","fw":4720,"group_id":2815158,"lts":23,"msm_id":2815158,"msm_name":"Tdig","prb_id":12534,"proto":"UDP","result":{"ANCOUNT":4,"ARCOUNT":5,"ID":24754,"NSCOUNT":4,"QDCOUNT":1,"abuf":"YLKEAAABAAQABAAFBHN0YXICY3MCdnUCbmwAAP8AAcAMAA0AAQABUYAACQNTdW4EVW5peMAMAA8AAQABUYAACwKaBnplcGh5csARwAwADwABAAFRgAAEAAHADMAMAAEAAQABUYAABMAf5yrAEQACAAEAAVGAAAYDdG9wwBHAEQACAAEAAVGAAAcEc29sb8ARwBEAAgABAAFRgAACwAzAEQACAAEAAVGAAAUCbnPAFMAMAAEAAQABUYAABMAf5yrAQgABAAEAAVGAAASCJRQKwKoAAQABAAFRgAAEgiWBBMB3AAEAAQABUYAABIIlFATAiQABAAEAAVGAAASCJRQF","rt":38.079,"size":255},"src_addr":"192.168.1.131","timestamp":1444999225,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], HinfoAnswer)) assert(result.responses[0].abuf.answers[0].name == "star.cs.vu.nl.") assert(result.responses[0].abuf.answers[0].ttl == 86400) assert(result.responses[0].abuf.answers[0].type == "HINFO") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 9) assert(result.responses[0].abuf.answers[0].cpu == "Sun") assert(result.responses[0].abuf.answers[0].os == "Unix") def test_mxanswer(): result = Result.get('{"from":"2607:fcc0:3:2:220:4aff:fee0:219e","msm_id":1687652,"fw":4610,"timestamp":1403098937,"resultset":[{"src_addr":"208.70.247.155","proto":"UDP","submax":3,"af":4,"subid":1,"result":{"abuf":"KESBgAABAAIAAAAABHJpcGUDbmV0AAAPAAHADAAPAAEAAAEsAAkAyARrb2tvwAzADAAPAAEAAAEsAAkA+gRrYWthwAw=","rt":198.454,"NSCOUNT":0,"QDCOUNT":1,"ID":10308,"ARCOUNT":0,"ANCOUNT":2,"size":68},"time":1403098937,"dst_addr":"208.70.244.7"},{"src_addr":"208.70.247.155","proto":"UDP","submax":3,"af":4,"subid":2,"result":{"abuf":"emqBgAABAAIAAAAABHJpcGUDbmV0AAAPAAHADAAPAAEAAAEsAAkAyARrb2tvwAzADAAPAAEAAAEsAAkA+gRrYWthwAw=","rt":127.644,"NSCOUNT":0,"QDCOUNT":1,"ID":31338,"ARCOUNT":0,"ANCOUNT":2,"size":68},"time":1403098938,"dst_addr":"208.70.245.7"},{"src_addr":"2607:fcc0:3:2:220:4aff:fee0:219e","proto":"UDP","submax":3,"af":6,"subid":3,"time":1403098939,"error":{"timeout":5000},"dst_addr":"2001:4860:4860::8888"}],"prb_id":2793,"group_id":1687652,"type":"dns","msm_name":"Tdig"}') assert(isinstance(result.responses[0].abuf.answers[0], MxAnswer)) assert(result.responses[0].abuf.answers[0].preference == 200) assert(result.responses[0].abuf.answers[0].mail_exchanger == "koko.ripe.net.") assert(result.responses[0].abuf.answers[0].name == "ripe.net.") assert(result.responses[0].abuf.answers[0].ttl == 300) assert(result.responses[0].abuf.answers[0].type == "MX") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 9) def test_nsanswer(): result = Result.get('{"from":"85.69.130.41","msm_id":1687666,"fw":4610,"timestamp":1403103973,"resultset":[{"src_addr":"10.0.50.116","proto":"UDP","submax":2,"af":4,"subid":1,"result":{"abuf":"sPKBgAABAAIAAAACCGpvaG5ib25kA29yZwAAAgABwAwAAgABAAAOEAAMA25zMQJoZQNuZXQAwAwAAgABAAAOEAAFAm5zwAzAQgABAAEAAVF\/AAS5IgCVwCoAAQABAABlRgAE2NqCAg==","rt":1688.621,"NSCOUNT":0,"QDCOUNT":1,"ID":45298,"ARCOUNT":2,"ANCOUNT":2,"size":103},"time":1403103973,"dst_addr":"10.0.0.34"},{"src_addr":"10.0.50.116","proto":"UDP","submax":2,"af":4,"subid":2,"result":{"abuf":"VkGBgAABAAIAAAACCGpvaG5ib25kA29yZwAAAgABwAwAAgABAAAOEAAFAm5zwAzADAACAAEAAA4QAAwDbnMxAmhlA25ldADAKgABAAEAAVGAAAS5IgCVwDsAAQABAAKjAAAE2NqCAg==","rt":932.26,"NSCOUNT":0,"QDCOUNT":1,"ID":22081,"ARCOUNT":2,"ANCOUNT":2,"size":103},"time":1403103976,"dst_addr":"10.0.0.35"}],"prb_id":17868,"group_id":1687666,"type":"dns","msm_name":"Tdig"}') assert(isinstance(result.responses[0].abuf.answers[0], NsAnswer)) assert(result.responses[0].abuf.answers[0].name == "johnbond.org.") assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].type == "NS") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 12) assert(result.responses[0].abuf.answers[0].target == "ns1.he.net.") def test_nsecanswer(): result = Result.get('{"af":6,"dst_addr":"2001:7fd::1","from":"2a02:1810:3505:de00:a2f3:c1ff:fec4:5ba8","fw":4720,"group_id":2815340,"lts":8,"msm_id":2815340,"msm_name":"Tdig","prb_id":11939,"proto":"UDP","result":{"ANCOUNT":0,"ARCOUNT":1,"ID":62350,"NSCOUNT":4,"QDCOUNT":1,"abuf":"846GAwABAAAABAABCGFhcmR2YXJrAAABAAEDYWFhAAAvAAEAAVGAAA0DYWJiAAAGIAAAAAATwBoALgABAAFRgACTAC8IAQABUYBWLbNQViB2QPRCAC/+fyqSx+gLHZaTO357C33yMzG6vpgWV0neGCUWr1i9g2a0Nc9w4o739PXvpDBQfkDmS6x4msfjU1lQv47U/9jMf7mOrWvlhKXZQ8ZPphqbNfa31h1pCNHu/NzBRLTdWJfMBMWuVbVJLdD/lEi/LW8G61fPbyFZfoM/crsfAkG6AAAvAAEAAVGAAA4DYWFhAAAHIgAAAAADgAAALgABAAFRgACTAC8IAAABUYBWLbNQViB2QPRCAJe1XkAFWiDj0V50PxlG3qSVux6rLfquyrII9HA2VMCLDeetkEgdtW+N7FWoh1Rampi7rho7R32O7HIk561bzdtP5lEA415RXus4Hf8BCXKgRtRoNJsFNAbkPKnbtRzNJAFDbP0mLfC08wSi0zsWRYDxaBLwh9ru/lJjOOR82UFhAAApEAAAAIAAAAA=","rt":18.193,"size":407},"src_addr":"2a02:1810:3505:de00:a2f3:c1ff:fec4:5ba8","timestamp":1445001458,"type":"dns"}') assert(isinstance(result.responses[0].abuf.authorities[0], NsecAnswer)) assert(result.responses[0].abuf.authorities[0].name == "aaa.") assert(result.responses[0].abuf.authorities[0].ttl == 86400) assert(result.responses[0].abuf.authorities[0].type == "NSEC") assert(result.responses[0].abuf.authorities[0].klass == "IN") assert(result.responses[0].abuf.authorities[0].rd_length == 13) assert(result.responses[0].abuf.authorities[0].next_domain_name == "abb.") assert(result.responses[0].abuf.authorities[0].types == [2, 43, 46, 47]) def test_nsec3answer(): result = Result.get('{"af":6,"dst_addr":"2a04:b900::1:0:0:12","from":"2a02:aa8:0:2000::10","fw":4700,"group_id":2815716,"lts":25,"msm_id":2815716,"msm_name":"Tdig","prb_id":11602,"proto":"UDP","result":{"ANCOUNT":0,"ARCOUNT":1,"ID":43793,"NSCOUNT":8,"QDCOUNT":1,"abuf":"qxGEAwABAAAACAABCGFhcmR2YXJrBW5sbmV0Am5sAAABAAEganVsaGZmZm1ycnNrdWF2czZicjhmZW01djdkbzU4cTnAFQAyAAEAAEZQABoBAAABABSnxvPOSUe3yFdR1MH6YM87p7jtScAjAC4AAQAARlAAnAAyCAMAAEZQVkPiQVYe+EGYQwVubG5ldAJubACU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isrhyMFJsyRgwFDWcvYqSeS6PSIMvdTb3vioHtKAAApEAAAAIAAAAA=","rt":37.356,"size":1019},"src_addr":"2a02:aa8:0:2000::10","timestamp":1445006271,"type":"dns"}') print(result.responses[0].abuf.authorities[2].flags) assert(isinstance(result.responses[0].abuf.authorities[2], Nsec3Answer)) assert(result.responses[0].abuf.authorities[2].name == "jc1h2mqech9kmgs1u24mpp6s72a4apbs.nlnet.nl.") assert(result.responses[0].abuf.authorities[2].ttl == 18000) assert(result.responses[0].abuf.authorities[2].type == "NSEC3") assert(result.responses[0].abuf.authorities[2].klass == "IN") assert(result.responses[0].abuf.authorities[2].rd_length == 41) assert(result.responses[0].abuf.authorities[2].hash_algorithm == 1) assert(result.responses[0].abuf.authorities[2].flags == 0) assert(result.responses[0].abuf.authorities[2].iterations == 1) assert(result.responses[0].abuf.authorities[2].salt == "") assert(result.responses[0].abuf.authorities[2].hash == "jd70d9265umj0a9jjnvg4skain4qpts6") assert(result.responses[0].abuf.authorities[2].types == [1, 2, 6, 15, 16, 28, 35, 46, 48, 51, 99]) def test_nsec3paramanswer(): result = Result.get('{"af":4,"dst_addr":"185.49.140.12","from":"78.27.190.13","fw":4720,"group_id":2816176,"lts":14,"msm_id":2816176,"msm_name":"Tdig","prb_id":12534,"proto":"UDP","result":{"ANCOUNT":24,"ARCOUNT":1,"ID":22156,"NSCOUNT":0,"QDCOUNT":1,"abuf":"VoyEAAABABgAAAABBW5sbmV0Am5sAAD/AAHADAAGAAEAAVGAADUCbnMJbmxuZXRsYWJzwBIKaG9zdG1hc3RlcgRvcGVuwAx4HAI8AABwgAAAHCAACTqAAABGUMAMAC4AAQABUYAAnAAGCAIAAVGAVkPiQVYe+EGYQwVubG5ldAJubACjw36l1w2NG2a7IoY1rE3dlyzzKU93Y6thZ6oSosbKPaaECdQzWDfrtgXozVAMFj19MXA94rU8FQnhg025UL+SaS1JiLNChErgtH8suLEid9kMDhr4dKdYOng12P4Srvo+2eorK4cjBSbMkYMBQ1nL2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Jz7CW2fYMrdBT5h4QvZk9PXidJq19NxQ5Di3vLFdQvoxT3RWSrXdKDfeWHx+PaIN3D6EymTfNDOyAAeDIxvVJAXglwC00AACkQAAAAgAAAAA==","answers":[{"MNAME":"ns.nlnetlabs.nl.","NAME":"nlnet.nl.","RNAME":"hostmaster.open.nlnet.nl.","SERIAL":2015101500,"TTL":86400,"TYPE":"SOA"}],"rt":39.686,"size":2770},"src_addr":"192.168.1.131","timestamp":1445010704,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[20], Nsec3ParamAnswer)) assert(result.responses[0].abuf.answers[20].name == 'nlnet.nl.') assert(result.responses[0].abuf.answers[20].ttl == 3600) assert(result.responses[0].abuf.answers[20].type == "NSEC3PARAM") assert(result.responses[0].abuf.answers[20].klass == "IN") assert(result.responses[0].abuf.answers[20].rd_length == 5) assert(result.responses[0].abuf.answers[20].algorithm == 1) assert(result.responses[0].abuf.answers[20].flags == 0) assert(result.responses[0].abuf.answers[20].iterations == 1) assert(result.responses[0].abuf.answers[20].salt == '') def test_ptranswer(): result = Result.get('{"af":6,"dst_addr":"2001:888:1044:10:2a0:c9ff:fe9f:17a9","from":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","fw":4700,"group_id":2827383,"lts":14,"msm_id":2827383,"msm_name":"Tdig","prb_id":12750,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":52292,"NSCOUNT":1,"QDCOUNT":1,"abuf":"zESEAAABAAEAAQAAATkBQQE3ATEBRgE5AUUBRgFGAUYBOQFDATABQQEyATABMAExATABMAE0ATQBMAExATgBOAE4ATABMQEwATABMgNpcDYEYXJwYQAADAABATkBYQE3ATEBZgE5AWUBZgFmAWYBOQFjATABYQEyATABMAExATABMAE0ATQBMAExATgBOAE4ATABMQEwATABMgNpcDYEYXJwYQAADAABAAAOEAAXB3N0ZXJlbzYCaHEGcGhpY29oA25ldADAggACAAEAAA4QAAYDbnMzwLk=","rt":34.676,"size":215},"src_addr":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","timestamp":1445246958,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], PtrAnswer)) assert(result.responses[0].abuf.answers[0].name == '9.a.7.1.f.9.e.f.f.f.9.c.0.a.2.0.0.1.0.0.4.4.0.1.8.8.8.0.1.0.0.2.ip6.arpa.') assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].type == "PTR") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 23) assert(result.responses[0].abuf.answers[0].target == 'stereo6.hq.phicoh.net.') def test_rrsiganswer(): result = Result.get('{"af":4,"dst_addr":"193.0.9.5","from":"188.134.80.2","fw":4670,"group_id":1863527,"lts":164,"msm_id":1863527,"msm_name":"Tdig","prb_id":10221,"proto":"UDP","result":{"ANCOUNT":2,"ARCOUNT":1,"ID":43644,"NSCOUNT":0,"QDCOUNT":1,"abuf":"qnyEAAABAAIAAAABA3d3dwRyaXBlA25ldAAAAQABwAwAAQABAABUYAAEwQAGi8AMAC4AAQAAVGAAnAABBQMAAFRgVQF0I1TZ2RP39gRyaXBlA25ldAAKTSpMfJr47JtCHrIXQlklDB4CoLtux0tTGbfOUYCL1XBcbCU9mRj9WHd52gkyDqPYT6IFF6i56xYAxidn1/9o2Ou+X2PGTt0L/Fb+Ht1CN3exboitJq2FnIC1jKUcJIWF3VcLg5AwLkOklifPJqAeeHL98BOZ4IdNC/jDSNHbRAAAKRAAAACAAAAA","rt":15.705,"size":225},"src_addr":"10.250.10.104","timestamp":1423566533,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[1], RRSigAnswer)) assert(result.responses[0].abuf.answers[1].type_covered == 'A') assert(result.responses[0].abuf.answers[1].algorithm == 5) assert(result.responses[0].abuf.answers[1].labels == 3) assert(result.responses[0].abuf.answers[1].original_ttl == 21600) assert(result.responses[0].abuf.answers[1].signature_expiration == 1426158627) assert(result.responses[0].abuf.answers[1].signature_inception == 1423563027) assert(result.responses[0].abuf.answers[1].key_tag == 63478) assert(result.responses[0].abuf.answers[1].signer_name == 'ripe.net.') assert(result.responses[0].abuf.answers[1].signature == 'Ck0qTHya+OybQh6yF0JZJQweAqC7bsdLUxm3zlGAi9VwXGwlPZkY/Vh3edoJMg6j2E+iBReouesWAMYnZ9f/aNjrvl9jxk7dC/xW/h7dQjd3sW6IrSathZyAtYylHCSFhd1XC4OQMC5DpJYnzyagHnhy/fATmeCHTQv4w0jR20Q=') def test_soaanswer(): result = Result.get('{"af":6,"dst_addr":"2001:dcd:7::1","from":"2a03:b280::280:a3ff:fe91:3bb2","fw":4610,"group_id":1674999,"msm_id":1675002,"msm_name":"Tdig","name":"2001:dcd:7:0:0:0:0:1","prb_id":3498,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":1,"ID":53767,"NSCOUNT":0,"QDCOUNT":1,"abuf":"0geEAAABAAEAAAABCHRlc3R6b25lAAAGAAHADAAGAAEAAAOEAEYDYXJpBWFscGhhBmFyaWRucwNuZXQCYXUAB3N1cHBvcnQLYXJpc2VydmljZXMDY29tAFOhbEUAAAcIAAABLAAbr4AAAAcIAAApEAAAAAAAAAwAAwAIZG5zMi5hbXM=","answers":[{"MNAME":"ari.alpha.aridns.net.au.","NAME":"testzone.","RNAME":"support.ariservices.com.","SERIAL":1403087941,"TTL":900,"TYPE":"SOA"}],"rt":21.566,"size":131},"result-rdata":null,"result-rname":"support.ariservices.com.","result-rt":21.566,"result-serial":1403087941,"src_addr":"2a03:b280::280:a3ff:fe91:3bb2","timestamp":1403087945,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], SoaAnswer)) assert(result.responses[0].abuf.answers[0].retry == 300) assert(result.responses[0].abuf.answers[0].name == 'testzone.') assert(result.responses[0].abuf.answers[0].minimum == 1800) assert(result.responses[0].abuf.answers[0].refresh == 1800) assert(result.responses[0].abuf.answers[0].mname == "ari.alpha.aridns.net.au.") assert(result.responses[0].abuf.answers[0].expire == 1814400) assert(result.responses[0].abuf.answers[0].rname == "support.ariservices.com.") assert(result.responses[0].abuf.answers[0].ttl == 900) assert(result.responses[0].abuf.answers[0].serial == 1403087941) assert(result.responses[0].abuf.answers[0].type == "SOA") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 70) def test_srvanswer(): result = Result.get('{"af":4,"dst_addr":"5.9.91.110","from":"213.169.87.0","fw":4720,"group_id":2827808,"lts":2,"msm_id":2827808,"msm_name":"Tdig","prb_id":11712,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":2,"ID":50101,"NSCOUNT":5,"QDCOUNT":1,"abuf":"w7WEAAABAAEABQACDF94bXBwLXNlcnZlcgRfdGNwCmJ1ZGR5Y2xvdWQDY29tAAAhAAHADAAhAAEAAAEsABsABQAAFJUEeG1wcApidWRkeWNsb3VkA2NvbQDASQACAAEAAAEsAAwDbnMyAmhlA25ldADASQACAAEAAAEsAAYDbnMzwGnASQACAAEAAAEsAAYDbnMxwEnASQACAAEAAAEsAAYDbnM0wGnASQACAAEAAAEsAAYDbnM1wGnARAABAAEAAAEsAAQFCVtuwI8AAQABAAABLAAEBQlbbg==","rt":39.476,"size":217},"src_addr":"192.168.1.145","timestamp":1445257644,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], SrvAnswer)) assert(result.responses[0].abuf.answers[0].name == '_xmpp-server._tcp.buddycloud.com.') assert(result.responses[0].abuf.answers[0].ttl == 300) assert(result.responses[0].abuf.answers[0].type == "SRV") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 27) assert(result.responses[0].abuf.answers[0].priority == 5) assert(result.responses[0].abuf.answers[0].weight == 0) assert(result.responses[0].abuf.answers[0].port == 5269) assert(result.responses[0].abuf.answers[0].target == 'xmpp.buddycloud.com.') def test_sshfpanswer(): result = Result.get('{"af":6,"dst_addr":"2001:67c:e0::5","from":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","fw":4700,"group_id":2828051,"lts":80,"msm_id":2828051,"msm_name":"Tdig","prb_id":12750,"proto":"UDP","result":{"ANCOUNT":5,"ARCOUNT":0,"ID":13066,"NSCOUNT":0,"QDCOUNT":1,"abuf":"MwqGAAABAAUAAAAABWJhbmtzBWF0bGFzBHJpcGUDbmV0AAD/AAHADAAcAAEAAFRgABAgAQZ8AugAEQAAAADBABMxwAwAAQABAABUYAAEwQATMcAMACwAAQAAVGAAFgEBXRM9wY0Cr3JqHks1Pm8TwyElyCDADAAsAAEAAFRgABYCAT5GQt0IOKjrSbJhxNhi9/IcKKtNwAwALwABAAABLAAjBGlwdjQFYmFua3MFYXRsYXMEcmlwZQNuZXQAAAZAAAAIAAs=","rt":17.846,"size":197},"src_addr":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","timestamp":1445260363,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[2], SshfpAnswer)) assert(result.responses[0].abuf.answers[2].name == 'banks.atlas.ripe.net.') assert(result.responses[0].abuf.answers[2].ttl == 21600) assert(result.responses[0].abuf.answers[2].type == "SSHFP") assert(result.responses[0].abuf.answers[2].klass == "IN") assert(result.responses[0].abuf.answers[2].rd_length == 22) assert(result.responses[0].abuf.answers[2].algorithm == 1) assert(result.responses[0].abuf.answers[2].digest_type == 1) assert(result.responses[0].abuf.answers[2].fingerprint == '5d133dc18d02af726a1e4b353e6f13c32125c820') def test_tlsaanswer(): result = Result.get('{"af":6,"dst_addr":"2001:67c:e0::5","from":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","fw":4700,"group_id":2828271,"lts":79,"msm_id":2828271,"msm_name":"Tdig","prb_id":12750,"proto":"UDP","result":{"ANCOUNT":4,"ARCOUNT":0,"ID":36436,"NSCOUNT":1,"QDCOUNT":1,"abuf":"jlSGAAABAAQAAQAABF80NDMEX3RjcAVhdGxhcwRyaXBlA25ldAAA/wABwAwANAABAAABLAAjAQAByKo6/qz2tjWS9PH44aqDIVYC/qQykybwJ4xFm54/I+nADAAvAAEAAAEsAB8FYWRtaW4FYXRsYXMEcmlwZQNuZXQAAAcAAAAAAAMIwAwALgABAAABLACcADQFBQAAASxWTEzQViSxwPQ+BHJpcGUDbmV0AG0lz8nbHKhBeKmPGKWAJ3oeQGRQpXbD9sKH2Hv/zrU5T2uXzufSq9ZsKJwx28x28mI5zbLgDoyCAiHlctdDNJLfPMpaHpZ/fw9095jnOvj9+iYAg6YiL1V/Pv5tSRbNvwHV1vIH7lb6YMASOBeifP4B/tszDDNKN6YzD+0ib+n5wAwALgABAAABLACcAC8FBQAAASxWTEzQViSxwPQ+BHJpcGUDbmV0AFOfKo+nqvdicU0rEmuXLJcQoHlNoxmnkWATtxT+AN6X2+Fd4RLQLRiqUXwj8cOE6VHfgeG/KHT9sETwKvrzKFS3wxO16Vd0ATqhIBshGtgb73WVFADrL2TKVSMxaHuXul6sWATeP5L4E4FFI9wW+RsxFB9kuFFeXOVVHH59B5OhwUoAAgABAAAOEAAOBnRpbm5pZQRhcmluwU8=","rt":17.932,"size":494},"src_addr":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","timestamp":1445263153,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], TlsaAnswer)) assert(result.responses[0].abuf.answers[0].name == '_443._tcp.atlas.ripe.net.') assert(result.responses[0].abuf.answers[0].ttl == 300) assert(result.responses[0].abuf.answers[0].type == "TLSA") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 35) assert(result.responses[0].abuf.answers[0].certificate_usage == 1) assert(result.responses[0].abuf.answers[0].selector == 0) assert(result.responses[0].abuf.answers[0].matching_type == 1) assert(result.responses[0].abuf.answers[0].certificate_associated_data == 'c8aa3afeacf6b63592f4f1f8e1aa83215602fea4329326f0278c459b9e3f23e9') def test_txtanswer(): result = Result.get('{"af":4,"dst_addr":"185.49.140.12","from":"78.27.190.13","fw":4720,"group_id":2816176,"lts":14,"msm_id":2816176,"msm_name":"Tdig","prb_id":12534,"proto":"UDP","result":{"ANCOU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tC5RQrO/zrDzT0EJXoo5T7CPR7f/FxacVfg3aobpPVrAKS1km+qjVOKMoAFNX3jfjK5xqhalVZHjBhgkp7yYofWWGwAwAYwABAAFRgABcW3Y9c3BmMSBpcDQ6MTg1LjQ5LjE0MC4wLzI0IGlwNjoyYTA0OmI5MDA6Oi82MyBpcDQ6MjEzLjE1NC4yMjQuMC8yNCBpcDY6MjAwMTo3Yjg6MjA2OjE6OjAvNjTADAAuAAEAAVGAAJwAYwgCAAFRgFZD4kFWHvhBmEMFbmxuZXQCbmwAJkDlwzJnuqvfNTKiblzm3iwrHYsmz/pTf/QNjTomn+efoVYoX12Lsou/LwiFrQstPYsdPjObhJQ9UvJz7CW2fYMrdBT5h4QvZk9PXidJq19NxQ5Di3vLFdQvoxT3RWSrXdKDfeWHx+PaIN3D6EymTfNDOyAAeDIxvVJAXglwC00AACkQAAAAgAAAAA==","answers":[{"MNAME":"ns.nlnetlabs.nl.","NAME":"nlnet.nl.","RNAME":"hostmaster.open.nlnet.nl.","SERIAL":2015101500,"TTL":86400,"TYPE":"SOA"}],"rt":39.686,"size":2770},"src_addr":"192.168.1.131","timestamp":1445010704,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[10], TxtAnswer)) assert(result.responses[0].abuf.answers[10].name == 'nlnet.nl.') assert(result.responses[0].abuf.answers[10].ttl == 86400) assert(result.responses[0].abuf.answers[10].type == "TXT") assert(result.responses[0].abuf.answers[10].klass == "IN") assert(result.responses[0].abuf.answers[10].rd_length == 16) assert(result.responses[0].abuf.answers[10].data == ['Stichting NLnet']) def test_unknownanswer(): result = Result.get('{"af":6,"dst_addr":"2001:888:1044:10:2a0:c9ff:fe9f:17a9","from":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","fw":4700,"group_id":2828518,"lts":17,"msm_id":2828518,"msm_name":"Tdig","prb_id":12750,"proto":"UDP","result":{"ANCOUNT":1,"ARCOUNT":0,"ID":5025,"NSCOUNT":0,"QDCOUNT":1,"abuf":"E6GGAAABAAEAAAAADHVua25vd24tdHlwZQRhaW95AmV1AAD/AAEMdW5rbm93bi10eXBlBGFpb3kCZXUA/wAAAQAADhAADEhlbGxvIFdvcmxkIQ==","rt":34.265,"size":82},"src_addr":"2001:920:6801:11:a2f3:c1ff:fec4:3fe7","timestamp":1445266555,"type":"dns"}') assert(isinstance(result.responses[0].abuf.answers[0], Answer)) assert(result.responses[0].abuf.answers[0].name == 'unknown-type.aioy.eu.') assert(result.responses[0].abuf.answers[0].ttl == 3600) assert(result.responses[0].abuf.answers[0].type == "65280") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 12) assert(result.responses[0].abuf.answers[0].rdata == '48656c6c6f20576f726c6421') def test_dns_lts(): result = Result.get('{"lts":161,"from":"46.17.16.18","msm_id":1004041,"timestamp":1406560725,"fw":4650,"proto":"UDP","af":4,"msm_name":"Tdig","prb_id":778,"result":{"abuf":"vb2EAAABAAEAAAAABWFzMjUwA25ldAAAAQABwAwAAQABAAAOEAAEwpaooA==","rt":36.661,"NSCOUNT":0,"QDCOUNT":1,"ID":48573,"ARCOUNT":0,"ANCOUNT":1,"size":43},"result-rt":36.661,"src_addr":"192.168.1.12","type":"dns","dst_addr":"193.227.234.53"}') assert(result.seconds_since_sync == 161) def test_txt_with_class_in(): result = Result.get('{"msm_id": 10209, "fw": 4660, "timestamp": 1413417973, "prb_id": 4232, "result": {"abuf": "nfCAgAABAAEAAAAAB3ZlcnNpb24EYmluZAAAEAADwAwAEAABAAAfMAAdHFBvd2VyRE5TIFJlY3Vyc29yIDMuNS4yICRJZCQ=", "rt": 298.828, "size": 71, "ARCOUNT": 0, "NSCOUNT": 0, "QDCOUNT": 1, "ANCOUNT": 1, "answers": [{"TYPE": "TXT", "NAME": "version.bind", "RDATA": "PowerDNS Recursor 3.5.2 $Id$"}], "ID": 40432}, "src_addr": "10.0.3.6", "msm_name": "Tdig", "lts": 71, "from": "89.179.73.12", "proto": "UDP", "af": 4, "type": "dns", "dst_addr": "198.41.0.4"}') print(result.responses[0].abuf.answers[0].raw_data) assert(result.responses[0].abuf.answers[0].name == "version.bind.") assert(result.responses[0].abuf.answers[0].klass == "IN") assert(result.responses[0].abuf.answers[0].rd_length == 29) assert(result.responses[0].abuf.answers[0].type == "TXT") assert(result.responses[0].abuf.answers[0].ttl == 7984) assert(len(result.responses[0].abuf.answers[0].data) == 1) assert(result.responses[0].abuf.answers[0].data[0] == "PowerDNS Recursor 3.5.2 $Id$") def test_unparsed_abuf(): result = Result.get('{"msm_id": 10209, "fw": 4660, "timestamp": 1413417973, "prb_id": 4232, "result": {"abuf": "nfCAgAABAAEAAAAAB3ZlcnNpb24EYmluZAAAEAADwAwAEAABAAAfMAAdHFBvd2VyRE5TIFJlY3Vyc29yIDMuNS4yICRJZCQ=", "rt": 298.828, "size": 71, "ARCOUNT": 0, "NSCOUNT": 0, "QDCOUNT": 1, "ANCOUNT": 1, "answers": [{"TYPE": "TXT", "NAME": "version.bind", "RDATA": "PowerDNS Recursor 3.5.2 $Id$"}], "ID": 40432}, "src_addr": "10.0.3.6", "msm_name": "Tdig", "lts": 71, "from": "89.179.73.12", "proto": "UDP", "af": 4, "type": "dns", "dst_addr": "198.41.0.4"}', parse_buf=False) assert(result.responses[0].abuf.answers[0].name == "version.bind") assert(result.responses[0].abuf.answers[0].klass is None) assert(result.responses[0].abuf.answers[0].rd_length is None) assert(result.responses[0].abuf.answers[0].type == "TXT") assert(result.responses[0].abuf.answers[0].ttl is None) assert(len(result.responses[0].abuf.answers[0].data) == 1) assert(result.responses[0].abuf.answers[0].data[0] == "PowerDNS Recursor 3.5.2 $Id$") def test_unparsed_abuf_with_txt_list(): result = Result.get('{"msm_id": 10209, "fw": 4660, "timestamp": 1413417973, "prb_id": 4232, "result": {"abuf": "nfCAgAABAAEAAAAAB3ZlcnNpb24EYmluZAAAEAADwAwAEAABAAAfMAAdHFBvd2VyRE5TIFJlY3Vyc29yIDMuNS4yICRJZCQ=", "rt": 298.828, "size": 71, "ARCOUNT": 0, "NSCOUNT": 0, "QDCOUNT": 1, "ANCOUNT": 1, "answers": [{"TYPE": "TXT", "NAME": "version.bind", "RDATA": ["PowerDNS Recursor 3.5.2 $Id$"]}], "ID": 40432}, "src_addr": "10.0.3.6", "msm_name": "Tdig", "lts": 71, "from": "89.179.73.12", "proto": "UDP", "af": 4, "type": "dns", "dst_addr": "198.41.0.4"}', parse_buf=False) assert(result.responses[0].abuf.answers[0].name == "version.bind") assert(result.responses[0].abuf.answers[0].klass is None) assert(result.responses[0].abuf.answers[0].rd_length is None) assert(result.responses[0].abuf.answers[0].type == "TXT") assert(result.responses[0].abuf.answers[0].ttl is None) assert(len(result.responses[0].abuf.answers[0].data) == 1) assert(result.responses[0].abuf.answers[0].data[0] == "PowerDNS Recursor 3.5.2 $Id$") def test_flags(): result = Result.get('{"from":"2001:67c:2e8:11::c100:136c","msm_id":1663540,"fw":4620,"af":6,"timestamp":1403091608,"proto":"UDP","dst_addr":"2001:41d0:1:4874::1","prb_id":6012,"result":{"abuf":"1jKEAAABAAEAAgADCnBvc3RtYXN0ZXICZnIAABwAAcAMABwAAQAAASwAECABQdAAAUh0AAAAAAAAAAHADAACAAEAAAEsAAYDbnMxwAzADAACAAEAAAEsAAYDbnMywAzARwABAAEAAAEsAARXYtl0wEcAHAABAAABLAAQIAFB0AABSHQAAAAAAAAAAcBZAAEAAQAAASwABFzzEZ8=","rt":8.656,"NSCOUNT":2,"QDCOUNT":1,"ANCOUNT":1,"ARCOUNT":3,"ID":54834,"size":155},"result-rt":8.656,"src_addr":"2001:67c:2e8:11::c100:136c","group_id":1663540,"type":"dns","msm_name":"Tdig","name":"2001:41d0:1:4874:0:0:0:1"}') Flags = namedtuple("Flags", ("qr", "aa", "tc", "rd", "ra", "z", "ad", "cd")) assert(result.responses[0].abuf.header.flags == Flags(qr=True, aa=True, tc=False, rd=False, ra=False, z=0, ad=False, cd=False)) def test_sections(): result = Result.get('{"from":"2001:67c:2e8:11::c100:136c","msm_id":1663540,"fw":4620,"af":6,"timestamp":1403091608,"proto":"UDP","dst_addr":"2001:41d0:1:4874::1","prb_id":6012,"result":{"abuf":"1jKEAAABAAEAAgADCnBvc3RtYXN0ZXICZnIAABwAAcAMABwAAQAAASwAECABQdAAAUh0AAAAAAAAAAHADAACAAEAAAEsAAYDbnMxwAzADAACAAEAAAEsAAYDbnMywAzARwABAAEAAAEsAARXYtl0wEcAHAABAAABLAAQIAFB0AABSHQAAAAAAAAAAcBZAAEAAQAAASwABFzzEZ8=","rt":8.656,"NSCOUNT":2,"QDCOUNT":1,"ANCOUNT":1,"ARCOUNT":3,"ID":54834,"size":155},"result-rt":8.656,"src_addr":"2001:67c:2e8:11::c100:136c","group_id":1663540,"type":"dns","msm_name":"Tdig","name":"2001:41d0:1:4874:0:0:0:1"}') Sections = namedtuple("Sections", ("QDCOUNT", "ANCOUNT", "NSCOUNT", "ARCOUNT")) assert(result.responses[0].abuf.header.sections == Sections(QDCOUNT=1, ANCOUNT=1, NSCOUNT=2, ARCOUNT=3)) def test_non_ascii_in_abuf(): result = Result.get('{"lts":136,"from":"83.163.117.153","msm_id":1020268,"fw":4670,"proto":"UDP","af":4,"msm_name":"Tdig","prb_id":96,"result":{"abuf":"sPKEAAABAAEAAQACB2RyYWdvbnMEYWlveQJldQAAEAABB2RyYWdvbnMEYWlveQJldQAAEAABAAAOEAATEkhlcmUgYmUg\/yBkcmFnb25zIcApAAIAAQAADhAABgNuczHAKcBbAAEAAQAADhAABIIlDyPAWwAcAAEAAA4QABAgAQiIEEQAEAKgyf\/+nxep","rt":33.973,"NSCOUNT":1,"QDCOUNT":1,"answers":[{"TYPE":"TXT","NAME":"dragons.aioy.eu","RDATA":"Here be \u00ff dragons!"}],"ID":45298,"ARCOUNT":2,"ANCOUNT":1,"size":141},"timestamp":1422535611,"src_addr":"10.0.1.61","group_id":1020268,"type":"dns","dst_addr":"130.37.15.35"}') assert(len(result.responses[0].abuf.answers) == 1) assert(len(result.responses[0].abuf.answers[0].data) == 1) assert(result.responses[0].abuf.answers[0].data[0] == "Here be \\255 dragons!") def test_quotes_in_multiline_txt_record(): result = Result.get('{"lts":136,"from":"83.163.117.153","msm_id":1020268,"fw":4670,"proto":"UDP","af":4,"msm_name":"Tdig","prb_id":96,"result":{"abuf":"sPKEAAABAAEAAgACB2RyYWdvbnMEYWlveQJldQAAEAABB2RyYWdvbnMEYWlveQJldQAAEAABAAAOEABPJUhlcmUgYmUg/yBkcmFnb25zISBXaXRoIFwgYW5kICIgYW5kIH8IYXMgd2VsbC4fVGhyb3dpbmcgaW4ggCBmb3IgZ29vZCBtZWFzdXJlLsApAAIAAQAADhAABgNuczHAKcApAAIAAQAADhAABgNuczLAKcCXAAEAAQAADhAABIIlDyPAqQAcAAEAAA4QABAgAQRw0WoAEAKgyf/+nxep","rt":33.973,"NSCOUNT":1,"QDCOUNT":1,"answers":[{"TYPE":"TXT","NAME":"dragons.aioy.eu","RDATA":"Here be \u00ff dragons!"}],"ID":45298,"ARCOUNT":2,"ANCOUNT":1,"size":141},"timestamp":1422535611,"src_addr":"10.0.1.61","group_id":1020268,"type":"dns","dst_addr":"130.37.15.35"}') assert result.responses[0].abuf.answers[0].data == [ "Here be \\255 dragons! With \\\\ and \\\" and \\127", "as well.", "Throwing in \\128 for good measure." ] assert result.responses[0].abuf.answers[0].data_string == "Here be \\255 dragons! With \\\\ and \\\" and \\127 as well. Throwing in \\128 for good measure." def test_string_representations(): # A result = Result.get('{"lts":0,"from":"2a02:8429:80a0:7c00:ea94:f6ff:fee3:643e","msm_id":1888719,"fw":4670,"proto":"UDP","af":6,"msm_name":"Tdig","prb_id":21567,"result":{"abuf":"ldWEAAABAAEAAAAAA3d3dwZlZHV0ZWwCbmwAAAEAAcAMAAEAAQABUYAABFfpweI=","rt":22.34,"NSCOUNT":0,"QDCOUNT":1,"ID":38357,"ARCOUNT":0,"ANCOUNT":1,"size":47},"timestamp":1425632241,"src_addr":"2a02:8429:80a0:7c00:ea94:f6ff:fee3:643e","group_id":1888719,"type":"dns","dst_addr":"2a02:2170:201:1::8"}') assert(str(result.responses[0].abuf.answers[0]) == "www.edutel.nl. 86400 IN A 87.233.193.226") # AAAA result = Result.get('{"from":"2a02:2b30:1:101:fa1a:67ff:fe52:eae5","msm_id":1032026,"fw":"4560","proto":"UDP","submax":1,"af":4,"dst_addr":"80.92.230.65","subid":1,"prb_id":12601,"result":{"abuf":"JZ2BgAABAAEAAQABCGJhc2VsaW5lBnJpcGU2NwlubG5ldGxhYnMCbmwAABwAAcAMABwAAQAAAB4AECoCKzAAAAEAAAAAAAAAABLAFQACAAEAABBkAAUCbnPAFcBWABwAAQAAEGQAECABB7gAQAAB0OEAAAAAAAI=","rt":69.793,"NSCOUNT":1,"QDCOUNT":1,"ID":9629,"ARCOUNT":1,"ANCOUNT":1,"size":119},"timestamp":1380927781,"src_addr":"80.92.230.185","type":"dns","msm_name":"Tdig"}') assert(str(result.responses[0].abuf.answers[0]) == "baseline.ripe67.nlnetlabs.nl. 30 IN AAAA 2a02:2b30:0:100:0:0:0:12") # NS result = Result.get('{"from":"2a02:2b30:1:101:fa1a:67ff:fe52:eae5","msm_id":1032026,"fw":"4560","proto":"UDP","submax":1,"af":4,"dst_addr":"80.92.230.65","subid":1,"prb_id":12601,"result":{"abuf":"JZ2BgAABAAEAAQABCGJhc2VsaW5lBnJpcGU2NwlubG5ldGxhYnMCbmwAABwAAcAMABwAAQAAAB4AECoCKzAAAAEAAAAAAAAAABLAFQACAAEAABBkAAUCbnPAFcBWABwAAQAAEGQAECABB7gAQAAB0OEAAAAAAAI=","rt":69.793,"NSCOUNT":1,"QDCOUNT":1,"ID":9629,"ARCOUNT":1,"ANCOUNT":1,"size":119},"timestamp":1380927781,"src_addr":"80.92.230.185","type":"dns","msm_name":"Tdig"}') assert(str(result.responses[0].abuf.answers[0]) == "baseline.ripe67.nlnetlabs.nl. 30 IN AAAA 2a02:2b30:0:100:0:0:0:12") # CNAME result = Result.get('{"lts":49,"from":"2a02:3a8:0:4::2","msm_id":2439409,"fw":4700,"timestamp":1442848754,"resultset":[{"lts":49,"src_addr":"193.91.33.126","proto":"TCP","submax":3,"af":4,"subid":1,"result":{"rt":3.408,"abuf":"B6qBgAABAAEABQAIA3d3dwV5YWhvbwNjb20AAAUAAcAMAAUAAQAAAOAADwZmZC1mcDMDd2cxAWLAEMAQAAIAAQACToMABgNuczPAEMAQAAIAAQACToMABgNuczLAEMAQAAIAAQACToMABgNuczTAEMAQAAIAAQACToMABgNuczHAEMAQAAIAAQACToMABgNuczXAEMB8AAEAAQAE34wABES0gxDAfAAcAAEAANWvABAgAUmYATAAAAAAAAAAABABwFgAAQABAAJ/ggAERI7/EMBYABwAAQABTgEAECABSZgBQAAAAAAAAAAAEALARgABAAEAAjXFAATLVN01wEYAHAABAAArWAAQJAaGAAC4/gMAAAAAAAAQA8BqAAEAAQAChBsABGKKC53AjgABAAEAAmOFAAR3oPd8","NSCOUNT":5,"QDCOUNT":1,"ID":1962,"ARCOUNT":8,"ANCOUNT":1,"size":312},"time":1442848754,"dst_addr":"217.31.66.232"},{"lts":50,"src_addr":"193.91.33.126","proto":"TCP","submax":3,"af":4,"subid":2,"result":{"rt":3.155,"abuf":"2qyBgAABAAEABQAIA3d3dwV5YWhvbwNjb20AAAUAAcAMAAUAAQAAAG4ADwZmZC1mcDMDd2cxAWLAEMAQAAIAAQACcl8ABgNuczXAEMAQAAIAAQACcl8ABgNuczHAEMAQAAIAAQACcl8ABgNuczPAEMAQAAIAAQACcl8ABgNuczLAEMAQAAIAAQACcl8ABgNuczTAEMBYAAEAAQAI7C0ABES0gxDAWAAcAAEAATc+ABAgAUmYATAAAAAAAAAAABABwHwAAQABAAj5qAAERI7/EMB8ABwAAQABNz4AECABSZgBQAAAAAAAAAAAEALAagABAAEABM+NAATLVN01wGoAHAABAAE3PgAQJAaGAAC4/gMAAAAAAAAQA8COAAEAAQAI7C0ABGKKC53ARgABAAEABM+NAAR3oPd8","NSCOUNT":5,"QDCOUNT":1,"ID":55980,"ARCOUNT":8,"ANCOUNT":1,"size":312},"time":1442848755,"dst_addr":"217.31.71.30"},{"lts":56,"src_addr":"193.91.33.126","proto":"TCP","submax":3,"af":6,"subid":3,"time":1442848756,"error":{"timeout":5000},"dst_addr":"2a02:3a8:100::100"}],"prb_id":18394,"group_id":2439409,"type":"dns","msm_name":"Tdig"}') assert(str(result.responses[0].abuf.answers[0]) == "www.yahoo.com. 224 IN CNAME fd-fp3.wg1.b.yahoo.com.") # MX result = Result.get('{"src_addr":"147.83.206.82","msm_id":1012182,"fw":4520,"timestamp":1372322532,"proto":"UDP","prb_id":4662,"af":4,"result":{"abuf":"gCOEAAABAAQAAgAGBW1leGlzA25ldAAADwABwAwADwABAAACWAAZAAoGZnJvbnQxDWVtYWlsc2VjdXJpdHnADMAMAA8AAQAAAlgACwAKBmZyb250MsAwwAwADwABAAACWAALAAoGZnJvbnQzwDDADAAPAAEAAAJYAAsACgZmcm9udDTAMMAMAAIAAQAAA4QAEANuczIJaW5mb2FjY2VzwBLADAACAAEAAAOEAAYDbnMxwJXAKQABAAEAAqMAAATP+U8kwE4AAQABAAKjAAAEz/lPJcBlAAEAAQACowAABM/5TybAfAABAAEAAqMAAATP+U8qwK0AAQABAAAOEAAEz/lD/cCRAAEAAQAAHCAABM/5Tf0=","rt":209.769,"NSCOUNT":2,"QDCOUNT":1,"ANCOUNT":4,"ARCOUNT":6,"ID":32803,"size":275},"type":"dns","dst_addr":"207.249.67.253"}') assert(str(result.responses[0].abuf.answers[0]) == "mexis.net. 600 IN MX 10 front1.emailsecurity.mexis.net.") # SOA result = Result.get('{"from":"2001:67c:2e8:13:220:4aff:fec6:cc9d","msm_id":1005129,"fw":"4570","af":6,"timestamp":1389966232,"proto":"UDP","msm_name":"Tdig","prb_id":9,"result":{"abuf":"NaCEAAABAAEACwALATQBNARlMTY0BGFycGEAAAYAAcAMAAYAAQACowAAOQNuczEDbmljAnVrAApob3N0bWFzdGVyB25vbWluZXQDb3JnwDNQ0vXjAAAcIAAAASwAJOoAAAAqMMAMAAIAAQACowAABgNuczPAL8AMAAIAAQACowAABgNuc2HAL8AMAAIAAQACowAABgNuczfAL8AMAAIAAQACowAABgNuc2TAL8AMAAIAAQACowAABgNuc2LAL8AMAAIAAQACowAABgNuczLAL8AMAAIAAQACowAABgNuc2PAL8AMAAIAAQACowAAAsArwAwAAgABAAKjAAAGA25zNMAvwAwAAgABAAKjAAAGA25zNcAvwAwAAgABAAKjAAAGA25zNsAvwCsAAQABAAKjAAAEw0LwgsArABwAAQACowAAECoBAEAQAQA1AAAAAAAAAALAygABAAEAAqMAAATZT6SDwHAAAQABAAKjAAAE1dsNg8D8AAEAAQACowAABMJT9IPA/AAcAAEAAqMAABAgAQYwAYEANQAAAAAAAACDwQ4AAQABAAKjAAAE1fang8EgAAEAAQACowAABNX4/oLAlAABAAEAAqMAAATUeSiCwIIAAQABAAKjAAAEnJpkA8CCABwAAQACowAAECABBQKtCQAAAAAAAAAAAAM=","rt":16.205,"NSCOUNT":11,"QDCOUNT":1,"answers":[{"RNAME":"hostmaster.nominet.org.uk.","NAME":"4.4.e164.arpa.","MNAME":"ns1.nic.uk.","TTL":172800,"SERIAL":1356002787,"TYPE":"SOA"}],"ANCOUNT":1,"ARCOUNT":11,"ID":13728,"size":506},"src_addr":"2001:67c:2e8:13:220:4aff:fec6:cc9d","type":"dns","dst_addr":"2a01:40:1001:35::2","name":"ns1.nic.uk"}') print(str(result.responses[0].abuf.answers[0])) assert(str(result.responses[0].abuf.answers[0]) == "4.4.e164.arpa. 172800 IN SOA ns1.nic.uk. hostmaster.nominet.org.uk. 1356002787 7200 300 2419200 10800") # DS result = Result.get('{"from":"2001:67c:2e8:11::c100:136c","msm_id":1665633,"fw":4620,"timestamp":1400801282,"resultset":[{"src_addr":"127.0.0.1","af":4,"submax":2,"proto":"UDP","subid":1,"result":{"abuf":"26SBgAABAAIAAAAADWF0dGFja3BsYW5uZXIDY29tAAArAAHADAArAAEAAN09ABhyzQgBFFW4DrGGzCGwpeh2g57Aru+SmW7ADAArAAEAAN09ACRyzQgCbb+EE82FAYk/5+rLzVV9JFVdBeTllqCu4EwDic/YGaw=","rt":0.275,"NSCOUNT":0,"QDCOUNT":1,"ANCOUNT":2,"ARCOUNT":0,"ID":56228,"size":119},"time":1400801282,"dst_addr":"127.0.0.1"},{"src_addr":"193.0.19.108","af":4,"submax":2,"proto":"UDP","subid":2,"result":{"abuf":"L0yBgAABAAIAAAAADWF0dGFja3BsYW5uZXIDY29tAAArAAHADAArAAEAAFRfACRyzQgCbb+EE82FAYk/5+rLzVV9JFVdBeTllqCu4EwDic/YGazADAArAAEAAFRfABhyzQgBFFW4DrGGzCGwpeh2g57Aru+SmW4=","rt":90.513,"NSCOUNT":0,"QDCOUNT":1,"ANCOUNT":2,"ARCOUNT":0,"ID":12108,"size":119},"time":1400801283,"dst_addr":"8.8.8.8"}],"prb_id":6012,"group_id":1665633,"type":"dns","msm_name":"Tdig"}') assert(str(result.responses[0].abuf.answers[0]) == "attackplanner.com. 56637 IN DS 29389 8 1 1455b80eb186cc21b0a5e876839ec0aeef92996e") assert(str(result.responses[0].abuf.answers[1]) == "attackplanner.com. 56637 IN DS 29389 8 2 6dbf8413cd8501893fe7eacbcd557d24555d05e4e596a0aee04c0389cfd819ac") # DNSKEY result = Result.get('{"lts":42,"from":"2001:df2:c00:900:c24a:ff:fecc:7938","msm_id":2392850,"fw":4700,"af":6,"timestamp":1441539311,"proto":"UDP","dst_addr":"240c:f:1:32::191","prb_id":19895,"result":{"abuf":"3y6EAAABAAMAAAABAAAwAAEAADAAAQABUYAAiAEAAwgDAQABvII3lhtZpiMzHDZyv67qQ1YDVURqv4srgiY7UMAnHqaNYhp4oaQ8pOxerUkMX1PGW4lERPY7jjphczKHH+Zd6d2itiv8DABew4Wkqgrc/Im3fCCQ7qa/wsgCeScBc3z0Gbj0PLwwZQjpET6mYGbttAuaoXeIhT27UIu6af7J/BsAADAAAQABUYABCAEBAwgDAQABy83PCnPGYP2+qafBCf+B/K6ZA1T1nPNNLQuP+63s4jxifdnr3WVVn8LjNpZpulrP7W1ZIgWr5fSd1iaktMo/E2iDh2GKYuDmnJHy+d2hh3w6/BpucWTK/zFoBz6XI7GFAmbGktJ6luV18ijMIMczK6lkRl1kEi2MPqNBQUAdYsgsebD9hQ24LOvuBgyQoUkRlhKNhvf95dcWomtUhvg8bheevpm3FX+whzMrSxY3c++NH+W1SAeoA4EceUaHJ4frScmZIMfkR77oPPs/Grrsts2jPxr9umojX8SvnZ6vH49wP/MBUWZ5FATUcac6jG289TAnVdEX2cW4KXJW7UVIIQAALgABAAFRgAETADAIAAABUYBWE6PTVewW0wvmAIZ3VP+pHu5o6u5sYU3biQwequ0b7ut2IWo2/cai8nSXLejXQeFkY1i7JlTNEKK6sHE/QGnO4x2AulHOIsbLm1VNwtDl42advEXQnojiIsH+nH4+vMP38ZLPn8eF1e5NE51ul8ixt9+2Z3SzH42B3i0AO0IiD7nfylgLJxt5m0LpNzL/DWn3aFWueSqJo6+hW/a4ghh1mRwQ+UQiO5ZR33AxNL8uZjKHSTogr0oEqklADtuaCuJJfLeEGh7gLIXmCgw59mRZEuNociaQUhFcx7EJ+GctR5Ht8EtDStHTVYtkvcjZlJZCAMYuo26X9+m+n1e6aDzasxDSD35GVnZfnHUAACkQAAAAgAAAAA==","rt":180.324,"NSCOUNT":0,"QDCOUNT":1,"ANCOUNT":3,"ARCOUNT":1,"ID":57134,"size":736},"src_addr":"2001:df2:c00:900:c24a:ff:fecc:7938","group_id":2392850,"type":"dns","msm_name":"Tdig"}') assert(str(result.responses[0].abuf.answers[0]) == ". 86400 IN DNSKEY 256 8 3 AwEAAbyCN5YbWaYjMxw2cr+u6kNWA1VEar+LK4ImO1DAJx6mjWIaeKGkPKTsXq1JDF9TxluJRET2O446YXMyhx/mXendorYr/AwAXsOFpKoK3PyJt3wgkO6mv8LIAnknAXN89Bm49Dy8MGUI6RE+pmBm7bQLmqF3iIU9u1CLumn+yfwb") assert(str(result.responses[0].abuf.answers[1]) == ". 86400 IN DNSKEY 257 8 3 AwEAAcvNzwpzxmD9vqmnwQn/gfyumQNU9ZzzTS0Lj/ut7OI8Yn3Z691lVZ/C4zaWabpaz+1tWSIFq+X0ndYmpLTKPxNog4dhimLg5pyR8vndoYd8OvwabnFkyv8xaAc+lyOxhQJmxpLSepbldfIozCDHMyupZEZdZBItjD6jQUFAHWLILHmw/YUNuCzr7gYMkKFJEZYSjYb3/eXXFqJrVIb4PG4Xnr6ZtxV/sIczK0sWN3PvjR/ltUgHqAOBHHlGhyeH60nJmSDH5Ee+6Dz7Pxq67LbNoz8a/bpqI1/Er52erx+PcD/zAVFmeRQE1HGnOoxtvPUwJ1XRF9nFuClyVu1FSCE=") assert(str(result.responses[0].abuf.answers[2]) == ". 86400 IN RRSIG DNSKEY 8 0 86400 20151006103459 20150906103459 3046 . hndU/6ke7mjq7mxhTduJDB6q7Rvu63Yhajb9xqLydJct6NdB4WRjWLsmVM0QorqwcT9Aac7jHYC6Uc4ixsubVU3C0OXjZp28RdCeiOIiwf6cfj68w/fxks+fx4XV7k0TnW6XyLG337ZndLMfjYHeLQA7QiIPud/KWAsnG3mbQuk3Mv8NafdoVa55Komjr6Fb9riCGHWZHBD5RCI7llHfcDE0vy5mModJOiCvSgSqSUAO25oK4kl8t4QaHuAsheYKDDn2ZFkS42hyJpBSEVzHsQn4Zy1Hke3wS0NK0dNVi2S9yNmUlkIAxi6jbpf36b6fV7poPNqzENIPfkZWdl+cdQ==") # TXT result = Result.get('{"lts":15,"from":"62.237.82.14","msm_id":1423386,"fw":4700,"proto":"UDP","af":4,"msm_name":"Tdig","prb_id":6036,"result":{"abuf":"iO6EAAABAAEAAQAACGhvc3RuYW1lBGJpbmQAABAAA8AMABAAAwAAAAAAFhVuczEuZmktaGVsLmsucmlwZS5uZXTADAACAAMAAAAAAALADA==","rt":1.347,"NSCOUNT":1,"QDCOUNT":1,"answers":[{"TYPE":"TXT","NAME":"hostname.bind","RDATA":"ns1.fi-hel.k.ripe.net"}],"ID":35054,"ARCOUNT":0,"ANCOUNT":1,"size":79},"timestamp":1442845198,"src_addr":"62.237.82.14","group_id":1423314,"type":"dns","dst_addr":"193.0.14.129"}') assert(str(result.responses[0].abuf.answers[0]) == "hostname.bind. 0 CH TXT ns1.fi-hel.k.ripe.net") # RRSIG result = Result.get('{"lts":17,"from":"62.245.181.100","msm_id":2355293,"fw":4700,"timestamp":1440751763,"resultset":[{"lts":17,"src_addr":"127.0.0.1","af":4,"submax":3,"proto":"UDP","subid":1,"result":{"abuf":"rqaBgAABAAEAAgAECGNvbm9zdGl4Amx1AAAuAAHADAAuAAEAAA4QAJ8AAggCAAAOEFYHp0xV4AyX5sQIY29ub3N0aXgCbHUAlLKDqgDxe5ARXC36xLHkCTVJHGXu2iPl8iN5MskUcOcgWx4eyj+M31AoN5kUfkhwJPiDQBtt1s5ULwItBa1dFuwjTaj/4DYzIp/n1Wn59ahLR60fhwpeZxVV7nhntbZplwSETDZ47nkfp5kOhikkaJtsh85hbLqA5pkYC/42qPjAOwACAAEAAKi/ABIDbnMxCGNvbm9zdGl4A2NvbQDAOwACAAEAAKi/AAYDbnMwwNjA8gABAAEAAqMAAAQfFngjwPIAHAABAAKjAAAQKgJvAADAAAEAAAAAAAAQNcDUAAEAAQACowAABLAfcaLA1AAcAAEAAqMAABAgAUHQAAg4ogAAAAAAABA1","rt":775.563,"NSCOUNT":2,"QDCOUNT":1,"ANCOUNT":1,"ARCOUNT":4,"ID":44710,"size":336},"time":1440751763,"dst_addr":"127.0.0.1"},{"lts":18,"src_addr":"2001:a60:91ea::16","af":6,"submax":3,"proto":"UDP","subid":2,"result":{"abuf":"UQKDgAABAAAAAAAACGNvbm9zdGl4Amx1AAAuAAE=","rt":67.873,"NSCOUNT":0,"QDCOUNT":1,"ANCOUNT":0,"ARCOUNT":0,"ID":20738,"size":29},"time":1440751765,"dst_addr":"2001:4860:4860::8888"},{"lts":19,"src_addr":"62.245.181.100","af":4,"submax":3,"proto":"UDP","subid":3,"result":{"abuf":"dkiDgAABAAAAAAAACGNvbm9zdGl4Amx1AAAuAAE=","rt":129.617,"NSCOUNT":0,"QDCOUNT":1,"ANCOUNT":0,"ARCOUNT":0,"ID":30280,"size":29},"time":1440751766,"dst_addr":"8.8.8.8"}],"prb_id":6123,"group_id":2355293,"type":"dns","msm_name":"Tdig"}') assert(str(result.responses[0].abuf.answers[0]) == "conostix.lu. 3600 IN RRSIG NS 8 2 3600 20150927082236 20150828072407 59076 conostix.lu. lLKDqgDxe5ARXC36xLHkCTVJHGXu2iPl8iN5MskUcOcgWx4eyj+M31AoN5kUfkhwJPiDQBtt1s5ULwItBa1dFuwjTaj/4DYzIp/n1Wn59ahLR60fhwpeZxVV7nhntbZplwSETDZ47nkfp5kOhikkaJtsh85hbLqA5pkYC/42qPg=") def test_error_propagation(): result = Result.get('{"lts":31,"from":"190.111.120.51","msm_id":10301,"fw":4700,"af":4,"timestamp":1443691516,"proto":"UDP","dst_addr":"193.0.14.129","prb_id":11180,"result":{"abuf":"NSSAhAAAAAAAAAAA","rt":1.282,"NSCOUNT":0,"QDCOUNT":0,"ANCOUNT":0,"ARCOUNT":0,"ID":13604,"size":12},"src_addr":"172.16.0.45","type":"dns","msm_name":"Tdig"}') assert(bool(result.responses[0].abuf)) assert(bool(result.responses[0].is_error)) ripe-atlas-sagan-1.3.1/tests/http.py000066400000000000000000000472021405365472700173610ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from ripe.atlas.sagan import Result, ResultError, ResultParseError from ripe.atlas.sagan.http import HttpResult def test_http_0(): data = '{"fw":0,"msm_id":12023,"prb_id":1,"src_addr":"GET4 193.0.6.139 0.042268 200 263 1406","timestamp":1319704299,"type":"http"}' result = Result.get(data) assert(result.is_malformed is True) try: Result.get(data, on_malformation=Result.ACTION_FAIL) assert False except ResultParseError: pass def test_http_1_error(): data = '{"fw":1,"msm_id":12023,"prb_id":1,"src_addr":"connect error 4","timestamp":1323118908,"type":"http"}' result = Result.get(data) assert(result.is_malformed is True) try: Result.get(data, on_malformation=Result.ACTION_FAIL) assert False except ResultParseError: pass def test_http_1(): result = Result.get('{"from":"62.194.83.50","fw":1,"msm_id":12023,"prb_id":1,"result":"GET4 193.0.6.139 0.030229 200 263 1406","timestamp":1333387900,"type":"http"}') assert(isinstance(result, HttpResult)) assert(result.origin == "62.194.83.50") assert(result.firmware == 1) assert(result.measurement_id == 12023) assert(result.probe_id == 1) assert(result.created.isoformat() == "2012-04-02T17:31:40+00:00") assert(result.uri is None) assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af is None) assert(result.responses[0].body_size == 1406) assert(result.responses[0].head_size == 263) assert(result.responses[0].destination_address == "193.0.6.139") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 30.229) assert(result.responses[0].source_address is None) assert(result.responses[0].version is None) def test_http_4430(): result = Result.get('{"from":"62.194.83.50","fw":4430,"msm_id":12023,"prb_id":1,"result":[{"addr":"193.0.6.139","bsize":1406,"hsize":263,"mode":"GET4","res":200,"rt":27.276,"srcaddr":"192.168.99.183","ver":"1.1"}],"timestamp":1336418202,"type":"http"}') assert(isinstance(result, HttpResult)) assert(result.origin == "62.194.83.50") assert(result.firmware == 4430) assert(result.measurement_id == 12023) assert(result.probe_id == 1) assert(result.created.isoformat() == "2012-05-07T19:16:42+00:00") assert(result.uri is None) assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af is None) assert(result.responses[0].body_size == 1406) assert(result.responses[0].head_size == 263) assert(result.responses[0].destination_address == "193.0.6.139") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 27.276) assert(result.responses[0].source_address == "192.168.99.183") assert(result.responses[0].version == "1.1") def test_http_4460(): result = Result.get('{"from":"2001:780:100:6:220:4aff:fee0:2479","fw":4460,"msm_id":1003930,"prb_id":2707,"result":[{"af":6,"bsize":22383,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":71.146000000000001,"src_addr":"2001:780:100:6:220:4aff:fee0:2479","ver":"1.1"}],"timestamp":1350471605,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2001:780:100:6:220:4aff:fee0:2479") assert(result.firmware == 4460) assert(result.measurement_id == 1003930) assert(result.probe_id == 2707) assert(result.created.isoformat() == "2012-10-17T11:00:05+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 22383) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 71.146) assert(result.responses[0].source_address == result.origin) assert(result.responses[0].version == "1.1") def test_http_4470(): result = Result.get('{"from":"2001:4538:100:0:220:4aff:fec8:232b","fw":4470,"msm_id":1003930,"prb_id":303,"result":[{"af":6,"bsize":22243,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":765.25400000000002,"src_addr":"2001:4538:100:0:220:4aff:fec8:232b","ver":"1.1"}],"timestamp":1352869218,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2001:4538:100:0:220:4aff:fec8:232b") assert(result.firmware == 4470) assert(result.measurement_id == 1003930) assert(result.probe_id == 303) assert(result.created.isoformat() == "2012-11-14T05:00:18+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 22243) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 765.254) assert(result.responses[0].source_address == result.origin) assert(result.responses[0].version == "1.1") def test_http_4480(): result = Result.get('{"fw":4480,"msm_id":1003930,"prb_id":2184,"result":[{"af":6,"bsize":39777,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":660.40999999999997,"src_addr":"2a02:6c80:5:0:220:4aff:fee0:2774","ver":"1.1"}],"src_addr":"2a02:6c80:5:0:220:4aff:fee0:2774","timestamp":1372582858,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin is None) assert(result.firmware == 4480) assert(result.measurement_id == 1003930) assert(result.probe_id == 2184) assert(result.created.isoformat() == "2013-06-30T09:00:58+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 39777) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 660.41) assert(result.responses[0].source_address == "2a02:6c80:5:0:220:4aff:fee0:2774") assert(result.responses[0].version == "1.1") def test_http_4500(): result = Result.get('{"from":"2a02:8304:1:4:220:4aff:fee0:228d","fw":4500,"msm_id":1003930,"prb_id":2954,"result":[{"af":6,"bsize":40103,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":234.048,"src_addr":"2a02:8304:1:4:220:4aff:fee0:228d","ver":"1.1"}],"timestamp":1367233244,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2a02:8304:1:4:220:4aff:fee0:228d") assert(result.firmware == 4500) assert(result.measurement_id == 1003930) assert(result.probe_id == 2954) assert(result.created.isoformat() == "2013-04-29T11:00:44+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 40103) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 234.048) assert(result.responses[0].source_address == result.origin) assert(result.responses[0].version == "1.1") def test_http_4520(): result = Result.get('{"from":"2a02:27d0:100:115:6000::250","fw":4520,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":2802,"result":[{"af":6,"bsize":40567,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":102.825,"src_addr":"2a02:27d0:100:115:6000::250","ver":"1.1"}],"timestamp":1379594363,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2a02:27d0:100:115:6000::250") assert(result.firmware == 4520) assert(result.measurement_id == 1003930) assert(result.probe_id == 2802) assert(result.created.isoformat() == "2013-09-19T12:39:23+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 40567) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 102.825) assert(result.responses[0].source_address == result.origin) assert(result.responses[0].version == "1.1") def test_http_4540(): result = Result.get('{"from":"2001:980:36af:1:220:4aff:fec8:226d","fw":4540,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":26,"result":[{"af":6,"bsize":40485,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":158.994,"src_addr":"2001:980:36af:1:220:4aff:fec8:226d","ver":"1.1"}],"timestamp":1377695803,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2001:980:36af:1:220:4aff:fec8:226d") assert(result.firmware == 4540) assert(result.measurement_id == 1003930) assert(result.probe_id == 26) assert(result.created.isoformat() == "2013-08-28T13:16:43+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 40485) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 158.994) assert(result.responses[0].source_address == "2001:980:36af:1:220:4aff:fec8:226d") assert(result.responses[0].version == "1.1") def test_http_4550(): result = Result.get('{"from":"2001:4538:100:0:220:4aff:fec8:232b","fw":4550,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":303,"result":[{"af":6,"bsize":40118,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":2092.447,"src_addr":"2001:4538:100:0:220:4aff:fec8:232b","ver":"1.1"}],"timestamp":1380901810,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2001:4538:100:0:220:4aff:fec8:232b") assert(result.firmware == 4550) assert(result.measurement_id == 1003930) assert(result.probe_id == 303) assert(result.created.isoformat() == "2013-10-04T15:50:10+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 40118) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 2092.447) assert(result.responses[0].source_address == "2001:4538:100:0:220:4aff:fec8:232b") assert(result.responses[0].version == "1.1") def test_http_4560(): result = Result.get('{"from":"2620:0:2ed0:aaaa::210","fw":4560,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":1164,"result":[{"af":6,"bsize":39340,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":739.26999999999998,"src_addr":"2620:0:2ed0:aaaa::210","ver":"1.1"}],"timestamp":1385895661,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2620:0:2ed0:aaaa::210") assert(result.firmware == 4560) assert(result.measurement_id == 1003930) assert(result.probe_id == 1164) assert(result.created.isoformat() == "2013-12-01T11:01:01+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 39340) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 739.27) assert(result.responses[0].source_address == "2620:0:2ed0:aaaa::210") assert(result.responses[0].version == "1.1") def test_http_4570(): result = Result.get('{"from":"2001:8b0:34f:5b8:220:4aff:fee0:21fc","fw":4570,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":2030,"result":[{"af":6,"bsize":41021,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":187.02199999999999,"src_addr":"2001:8b0:34f:5b8:220:4aff:fee0:21fc","ver":"1.1"}],"timestamp":1395324614,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2001:8b0:34f:5b8:220:4aff:fee0:21fc") assert(result.firmware == 4570) assert(result.measurement_id == 1003930) assert(result.probe_id == 2030) assert(result.created.isoformat() == "2014-03-20T14:10:14+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 41021) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 187.022) assert(result.responses[0].source_address == "2001:8b0:34f:5b8:220:4aff:fee0:21fc") assert(result.responses[0].version == "1.1") def test_http_4600(): result = Result.get('{"from":"2a01:6a8:0:f:220:4aff:fec5:5b5a","fw":4600,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":720,"result":[{"af":6,"bsize":41020,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":195.84399999999999,"src_addr":"2a01:6a8:0:f:220:4aff:fec5:5b5a","ver":"1.1"}],"timestamp":1396163194,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2a01:6a8:0:f:220:4aff:fec5:5b5a") assert(result.firmware == 4600) assert(result.measurement_id == 1003930) assert(result.probe_id == 720) assert(result.created.isoformat() == "2014-03-30T07:06:34+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 41020) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 195.844) assert(result.responses[0].source_address == "2a01:6a8:0:f:220:4aff:fec5:5b5a") assert(result.responses[0].version == "1.1") def test_http_4610(): result = Result.get('{"from":"2a01:9e00:a217:d00:220:4aff:fec6:cb5b","fw":4610,"group_id":1003930,"msm_id":1003930,"msm_name":"HTTPGet","prb_id":780,"result":[{"af":6,"bsize":41020,"dst_addr":"2001:67c:2e8:22::c100:68b","hsize":279,"method":"GET","res":200,"rt":154.755,"src_addr":"2a01:9e00:a217:d00:220:4aff:fec6:cb5b","ver":"1.1"}],"timestamp":1396359320,"type":"http","uri":"http://www.ripe.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2a01:9e00:a217:d00:220:4aff:fec6:cb5b") assert(result.firmware == 4610) assert(result.measurement_id == 1003930) assert(result.probe_id == 780) assert(result.created.isoformat() == "2014-04-01T13:35:20+00:00") assert(result.uri == "http://www.ripe.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size == 41020) assert(result.responses[0].head_size == 279) assert(result.responses[0].destination_address == "2001:67c:2e8:22::c100:68b") assert(result.responses[0].code == 200) assert(result.responses[0].response_time == 154.755) assert(result.responses[0].source_address == "2a01:9e00:a217:d00:220:4aff:fec6:cb5b") assert(result.responses[0].version == "1.1") def test_http_4610_fail(): result = Result.get('{"from":"2001:630:301:1080:220:4aff:fee0:20a0","fw":4610,"msm_id":1003932,"msm_name":"HTTPGet","prb_id":2493,"result":[{"af":6,"dst_addr":"2001:42d0:0:200::6","err":"timeout reading chunk","method":"GET","src_addr":"2001:630:301:1080:220:4aff:fee0:20a0"}],"timestamp":1398184661,"type":"http","uri":"http://www.afrinic.net/"}') assert(isinstance(result, HttpResult)) assert(result.origin == "2001:630:301:1080:220:4aff:fee0:20a0") assert(result.firmware == 4610) assert(result.measurement_id == 1003932) assert(result.probe_id == 2493) assert(result.created.isoformat() == "2014-04-22T16:37:41+00:00") assert(result.uri == "http://www.afrinic.net/") assert(result.method == HttpResult.METHOD_GET) assert(isinstance(result.responses, list)) assert(len(result.responses) == 1) assert(result.responses[0].af == 6) assert(result.responses[0].body_size is None) assert(result.responses[0].head_size is None) assert(result.responses[0].destination_address == "2001:42d0:0:200::6") assert(result.responses[0].code is None) assert(result.responses[0].response_time is None) assert(result.responses[0].source_address == "2001:630:301:1080:220:4aff:fee0:20a0") assert(result.responses[0].version is None) assert(result.responses[0].is_error is True) assert(result.responses[0].error_message == "timeout reading chunk") def test_http_lts(): result = Result.get('{"lts":275,"from":"","msm_id":1003932,"fw":4650,"timestamp":1406558081,"uri":"http:\/\/www.afrinic.net\/","prb_id":902,"result":[{"method":"GET","dst_addr":"2001:42d0:0:200::6","err":"connect: Network is unreachable","af":6}],"type":"http","msm_name":"HTTPGet"}') assert(result.seconds_since_sync == 275) ripe-atlas-sagan-1.3.1/tests/ntp.py000066400000000000000000000151471405365472700172060ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from ripe.atlas.sagan import Result from ripe.atlas.sagan.ntp import NtpResult def test_ntp_valid(): result = ( '{"af":4,"dst_addr":"193.0.0.229","dst_name":"atlas","from":"193.0.0.78","fw":4670,' '"group_id":1020237,"li":"no","lts":-1,"mode":"server","msm_id":1020237,"msm_name":"Ntp",' '"poll":1,"prb_id":71,"precision":0.0000019074,"proto":"UDP","ref-id":"GPS",' '"ref-ts":3627199357.7446351051,"result":[' '{"final-ts":3627199379.8182010651,"offset":-8.363271,"origin-ts":3627199379.7962741852,' '"receive-ts":3627199388.1704945564,"rtt":0.021899,"transmit-ts":3627199388.170522213},' '{"final-ts":3627199379.831638813,"offset":-8.36871,"origin-ts":3627199379.8214530945,' '"receive-ts":3627199388.1952428818,"rtt":0.01016,"transmit-ts":3627199388.195268631},' '{"final-ts":3627199379.8474769592,"offset":-8.372775,"origin-ts":3627199379.8454480171,' '"receive-ts":3627199388.2192249298,"rtt":0.002004,"transmit-ts":3627199388.2192502022}' '],' '"root-delay":0,"root-dispersion":0.00140381,"src_addr":"10.0.2.12","stratum":1,' '"timestamp":1418210579,"type":"ntp","version":4}' ) result = Result.get(result) assert(isinstance(result, NtpResult)) assert(result.af == 4) assert(result.firmware == 4670) assert(result.destination_address == "193.0.0.229") assert(result.destination_name == "atlas") assert(result.source_address == "10.0.2.12") assert(result.origin == "193.0.0.78") assert(result.leap_second_indicator == "no") assert(result.mode == "server") assert(result.poll == 1) assert(result.precision == 1.9074e-06) assert(result.protocol == "UDP") assert(result.reference_id == "GPS") assert(result.reference_time == 3627199357.7446351051) assert(result.root_delay == 0) assert(round(result.root_dispersion, 8) == 0.00140381) assert(result.stratum == 1) assert(result.version == 4) assert(result.packets[0].final_timestamp == 3627199379.8182010651) assert(result.packets[0].final_time.isoformat() == "2014-12-10T11:22:59.818201+00:00") assert(result.packets[0].offset == -8.363271) assert(result.packets[0].rtt == 0.022) assert(result.packets[0].origin_timestamp == 3627199379.7962741852) assert(result.packets[0].origin_time.isoformat() == "2014-12-10T11:22:59.796274+00:00") assert(result.packets[0].received_timestamp == 3627199388.1704945564) assert(result.packets[0].received_time.isoformat() == "2014-12-10T11:23:08.170495+00:00") assert(result.packets[0].transmitted_timestamp == 3627199388.170522213) assert(result.packets[0].transmitted_time.isoformat() == "2014-12-10T11:23:08.170522+00:00") assert(result.rtt_min == 0.002) assert(result.rtt_max == 0.022) assert(result.rtt_median == 0.01) assert(result.offset_min == -8.372775) assert(result.offset_max == -8.363271) assert(result.offset_median == -8.36871) def test_ntp_timeout(): result = ( '{ "msm_id":"1020235", "fw":4661, "lts":76, "timestamp":1418196642, "dst_name":"atlas", ' '"prb_id":71, "dst_addr":"193.0.6.139", "src_addr":"193.0.10.127", "proto":"UDP", "af": 4,' '"from": "193.0.0.78", "type": "ntp", "result": ' '[ { "x":"*" }, { "x":"*" }, { "x":"*" } ] ' '}' ) result = Result.get(result) assert(isinstance(result, NtpResult)) assert(result.af == 4) assert(result.firmware == 4661) assert(result.destination_address == "193.0.6.139") assert(result.destination_name == "atlas") assert(result.source_address == "193.0.10.127") assert(result.origin == "193.0.0.78") assert(result.leap_second_indicator is None) assert(result.stratum is None) assert(result.rtt_median is None) assert(result.offset_median is None) assert(getattr(result.packets[0], "final_timestamp", None) is None) assert(getattr(result.packets[0], "final_times", None) is None) assert(getattr(result.packets[0], "origin_timestamp", None) is None) assert(getattr(result.packets[0], "origin_time", None) is None) assert(getattr(result.packets[0], "transmitted_timestamp", None) is None) assert(getattr(result.packets[0], "transmitted_time", None) is None) assert(getattr(result.packets[0], "received_timestamp", None) is None) assert(getattr(result.packets[0], "received_time", None) is None) assert(result.packets[0].offset is None) assert(result.packets[0].rtt is None) def test_ntp_error(): result = ( '{ "msm_id":"1020235", "fw":4661, "lts":76, "timestamp":1418196642, "dst_name":"atlas", ' '"prb_id":71, "dst_addr":"193.0.6.139", "src_addr":"193.0.10.127", "proto":"UDP", "af": 4,' '"from": "193.0.0.78", "type": "ntp", "result": ' '[ { "error":"error-example" }, { "error":"error-example" }, { "x":"*" } ] ' '}' ) result = Result.get(result) assert(isinstance(result, NtpResult)) assert(result.af == 4) assert(result.firmware == 4661) assert(result.destination_address == "193.0.6.139") assert(result.destination_name == "atlas") assert(result.source_address == "193.0.10.127") assert(result.origin == "193.0.0.78") assert(result.leap_second_indicator is None) assert(result.stratum is None) assert(result.rtt_median is None) assert(result.offset_median is None) assert(getattr(result.packets[0], "final_timestamp", None) is None) assert(getattr(result.packets[0], "final_time", None) is None) assert(getattr(result.packets[0], "origin_timestamp", None) is None) assert(getattr(result.packets[0], "origin_time", None) is None) assert(getattr(result.packets[0], "transmitted_timestamp", None) is None) assert(getattr(result.packets[0], "transmitted_time", None) is None) assert(getattr(result.packets[0], "received_timestamp", None) is None) assert(getattr(result.packets[0], "received_time", None) is None) assert(result.packets[0].offset is None) assert(result.packets[0].rtt is None) ripe-atlas-sagan-1.3.1/tests/ping.py000066400000000000000000000636511405365472700173450ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from ripe.atlas.sagan import Result from ripe.atlas.sagan.ping import PingResult, Packet def test_ping_0(): result = Result.get('{"avg":"58.042","dst_addr":"62.2.16.12","dup":"0","fw":0,"max":"58.272","min":"57.876","msm_id":1000192,"prb_id":677,"rcvd":"3","sent":"3","src_addr":"78.128.9.202","timestamp":1328019792,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 58.042) assert(result.rtt_median is None) assert(result.destination_address == "62.2.16.12") assert(result.destination_name is None) assert(result.duplicates == 0) assert(result.origin is None) assert(result.firmware == 0) assert(result.seconds_since_sync is None) assert(result.rtt_max == 58.272) assert(result.rtt_min == 57.876) assert(result.measurement_id == 1000192) assert(result.probe_id == 677) assert(result.protocol is None) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size is None) assert(result.step is None) assert(result.created.isoformat() == "2012-01-31T14:23:12+00:00") assert(result.packets == []) def test_ping_1(): result = Result.get('{"addr":"62.2.16.12","avg":124.572,"dup":0,"from":"194.85.27.7","fw":1,"max":125.44499999999999,"min":123.89400000000001,"msm_id":1000192,"name":"hsi.cablecom.ch","prb_id":165,"rcvd":3,"sent":3,"size":56,"timestamp":1340523908,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 124.572) assert(result.rtt_median is None) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "194.85.27.7") assert(result.firmware == 1) assert(result.seconds_since_sync is None) assert(result.rtt_max == 125.445) assert(result.rtt_min == 123.894) assert(result.measurement_id == 1000192) assert(result.probe_id == 165) assert(result.protocol is None) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size is None) assert(result.step is None) assert(result.created.isoformat() == "2012-06-24T07:45:08+00:00") assert(result.packets == []) def test_ping_4460(): result = Result.get('{"addr":"62.2.16.12","af":4,"avg":48.388333333333328,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"188.194.234.136","fw":4460,"max":56.948999999999998,"min":43.869999999999997,"msm_id":1000192,"name":"hsi.cablecom.ch","prb_id":270,"proto":"ICMP","rcvd":3,"result":[{"rtt":43.869999999999997},{"rtt":56.948999999999998},{"rtt":44.345999999999997}],"sent":3,"size":20,"src_addr":"192.168.178.21","timestamp":1340524626,"ttl":52,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 48.388) assert(result.rtt_median == 44.346) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "188.194.234.136") assert(result.firmware == 4460) assert(result.seconds_since_sync is None) assert(result.rtt_max == 56.949) assert(result.rtt_min == 43.87) assert(result.measurement_id == 1000192) assert(result.probe_id == 270) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step is None) assert(result.created.isoformat() == "2012-06-24T07:57:06+00:00") assert(result.packets[0].rtt == 43.87) assert(result.packets[1].rtt == 56.949) assert(result.packets[2].rtt == 44.346) assert(result.packets[0].ttl == 52) assert(result.packets[1].ttl == 52) assert(result.packets[2].ttl == 52) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.178.21") assert(result.packets[1].source_address == "192.168.178.21") assert(result.packets[2].source_address == "192.168.178.21") def test_ping_4470(): result = Result.get('{"addr":"62.2.16.12","af":4,"avg":195.649,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"194.85.27.7","fw":4470,"max":197.79300000000001,"min":193.059,"msm_id":1000192,"name":"hsi.cablecom.ch","prb_id":165,"proto":"ICMP","rcvd":3,"result":[{"rtt":196.095},{"rtt":197.79300000000001},{"rtt":193.059}],"sent":3,"size":20,"src_addr":"192.168.3.8","timestamp":1344514151,"ttl":46,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 195.649) assert(result.rtt_median == 196.095) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "194.85.27.7") assert(result.firmware == 4470) assert(result.seconds_since_sync is None) assert(result.rtt_max == 197.793) assert(result.rtt_min == 193.059) assert(result.measurement_id == 1000192) assert(result.probe_id == 165) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step is None) assert(result.created.isoformat() == "2012-08-09T12:09:11+00:00") assert(result.packets[0].rtt == 196.095) assert(result.packets[1].rtt == 197.793) assert(result.packets[2].rtt == 193.059) assert(result.packets[0].ttl == 46) assert(result.packets[1].ttl == 46) assert(result.packets[2].ttl == 46) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.3.8") assert(result.packets[1].source_address == "192.168.3.8") assert(result.packets[2].source_address == "192.168.3.8") def test_ping_4480(): result = Result.get('{"addr":"62.2.16.12","af":4,"avg":95.756666666666661,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"194.85.27.7","fw":4480,"max":96.147999999999996,"min":95.388999999999996,"msm_id":1000192,"name":"hsi.cablecom.ch","prb_id":165,"proto":"ICMP","rcvd":3,"result":[{"rtt":95.733000000000004},{"rtt":96.147999999999996},{"rtt":95.388999999999996}],"sent":3,"size":20,"src_addr":"192.168.3.8","timestamp":1349776268,"ttl":46,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 95.757) assert(result.rtt_median == 95.733) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "194.85.27.7") assert(result.firmware == 4480) assert(result.seconds_since_sync is None) assert(result.rtt_max == 96.148) assert(result.rtt_min == 95.389) assert(result.measurement_id == 1000192) assert(result.probe_id == 165) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step is None) assert(result.created.isoformat() == "2012-10-09T09:51:08+00:00") assert(result.packets[0].rtt == 95.733) assert(result.packets[1].rtt == 96.148) assert(result.packets[2].rtt == 95.389) assert(result.packets[0].ttl == 46) assert(result.packets[1].ttl == 46) assert(result.packets[2].ttl == 46) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.3.8") assert(result.packets[1].source_address == "192.168.3.8") assert(result.packets[2].source_address == "192.168.3.8") def test_ping_4500(): result = Result.get('{"addr":"62.2.16.12","af":4,"avg":30.114666666666665,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"80.56.151.3","fw":4500,"max":30.344999999999999,"min":29.960999999999999,"msm_id":1000192,"name":"hsi.cablecom.ch","prb_id":202,"proto":"ICMP","rcvd":3,"result":[{"rtt":30.038},{"rtt":29.960999999999999},{"rtt":30.344999999999999}],"sent":3,"size":20,"src_addr":"192.168.1.229","timestamp":1361244431,"ttl":55,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 30.115) assert(result.rtt_median == 30.038) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "80.56.151.3") assert(result.firmware == 4500) assert(result.seconds_since_sync is None) assert(result.rtt_max == 30.345) assert(result.rtt_min == 29.961) assert(result.measurement_id == 1000192) assert(result.probe_id == 202) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step is None) assert(result.created.isoformat() == "2013-02-19T03:27:11+00:00") assert(result.packets[0].rtt == 30.038) assert(result.packets[1].rtt == 29.961) assert(result.packets[2].rtt == 30.345) assert(result.packets[0].ttl == 55) assert(result.packets[1].ttl == 55) assert(result.packets[2].ttl == 55) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.1.229") assert(result.packets[1].source_address == "192.168.1.229") assert(result.packets[2].source_address == "192.168.1.229") def test_ping_4520(): result = Result.get('{"addr":"62.2.16.12","af":4,"avg":67.420999999999992,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"194.85.27.7","fw":4520,"max":70.230999999999995,"min":65.974999999999994,"msm_id":1000192,"name":"hsi.cablecom.ch","prb_id":165,"proto":"ICMP","rcvd":3,"result":[{"rtt":70.230999999999995},{"rtt":65.974999999999994},{"rtt":66.057000000000002}],"sent":3,"size":20,"src_addr":"192.168.3.8","timestamp":1365379380,"ttl":47,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 67.421) assert(result.rtt_median == 66.057) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "194.85.27.7") assert(result.firmware == 4520) assert(result.seconds_since_sync is None) assert(result.rtt_max == 70.231) assert(result.rtt_min == 65.975) assert(result.measurement_id == 1000192) assert(result.probe_id == 165) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step is None) assert(result.created.isoformat() == "2013-04-08T00:03:00+00:00") assert(result.packets[0].rtt == 70.231) assert(result.packets[1].rtt == 65.975) assert(result.packets[2].rtt == 66.057) assert(result.packets[0].ttl == 47) assert(result.packets[1].ttl == 47) assert(result.packets[2].ttl == 47) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.3.8") assert(result.packets[1].source_address == "192.168.3.8") assert(result.packets[2].source_address == "192.168.3.8") def test_ping_4550(): result = Result.get('{"af":4,"avg":27.300999999999998,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"80.56.151.3","fw":4550,"lts":365,"max":27.300999999999998,"min":27.300999999999998,"msm_id":1000192,"msm_name":"Ping","prb_id":202,"proto":"ICMP","rcvd":1,"result":[{"srcaddr":"192.168.1.229","x":"*"},{"x":"*"},{"rtt":27.300999999999998,"ttl":54}],"sent":3,"size":20,"src_addr":"192.168.1.229","step":360,"timestamp":1378271710,"ttl":54,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 27.301) assert(result.rtt_median == 27.301) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "80.56.151.3") assert(result.firmware == 4550) assert(result.seconds_since_sync == 365) assert(result.rtt_max == 27.301) assert(result.rtt_min == 27.301) assert(result.measurement_id == 1000192) assert(result.probe_id == 202) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 1) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step == 360) assert(result.created.isoformat() == "2013-09-04T05:15:10+00:00") assert(result.packets[0].rtt is None) assert(result.packets[1].rtt is None) assert(result.packets[2].rtt == 27.301) assert(result.packets[0].ttl is None) assert(result.packets[1].ttl is None) assert(result.packets[2].ttl == 54) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.1.229") assert(result.packets[1].source_address == "192.168.1.229") assert(result.packets[2].source_address == "192.168.1.229") def test_ping_4560(): result = Result.get('{"af":4,"avg":36.887,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"62.195.143.53","fw":4560,"lts":36,"max":40.234000000000002,"min":34.747999999999998,"msm_id":1000192,"msm_name":"Ping","prb_id":202,"proto":"ICMP","rcvd":3,"result":[{"rtt":40.234000000000002},{"rtt":34.747999999999998,"srcaddr":"192.168.1.229"},{"rtt":35.679000000000002,"srcaddr":"192.168.1.229"}],"sent":3,"size":20,"src_addr":"192.168.1.229","step":360,"timestamp":1380586151,"ttl":54,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 36.887) assert(result.rtt_median == 35.679) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "62.195.143.53") assert(result.firmware == 4560) assert(result.seconds_since_sync is 36) assert(result.rtt_max == 40.234) assert(result.rtt_min == 34.748) assert(result.measurement_id == 1000192) assert(result.probe_id == 202) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step == 360) assert(result.created.isoformat() == "2013-10-01T00:09:11+00:00") assert(result.packets[0].rtt == 40.234) assert(result.packets[1].rtt == 34.748) assert(result.packets[2].rtt == 35.679) assert(result.packets[0].ttl == 54) assert(result.packets[1].ttl == 54) assert(result.packets[2].ttl == 54) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.1.229") assert(result.packets[1].source_address == "192.168.1.229") assert(result.packets[2].source_address == "192.168.1.229") def test_ping_4570(): result = Result.get('{"af":4,"avg":36.608333333333327,"dst_addr":"62.2.16.12","dst_name":"hsi.cablecom.ch","dup":0,"from":"62.195.143.53","fw":4570,"lts":-1,"max":36.741,"min":36.423999999999999,"msm_id":1000192,"msm_name":"Ping","prb_id":202,"proto":"ICMP","rcvd":3,"result":[{"rtt":36.741},{"rtt":36.659999999999997},{"rtt":36.423999999999999}],"sent":3,"size":12,"step":360,"timestamp":1384500425, "type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 36.608) assert(result.rtt_median == 36.66) assert(result.destination_address == "62.2.16.12") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "62.195.143.53") assert(result.firmware == 4570) assert(result.seconds_since_sync is None) assert(result.rtt_max == 36.741) assert(result.rtt_min == 36.424) assert(result.measurement_id == 1000192) assert(result.probe_id == 202) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step == 360) assert(result.created.isoformat() == "2013-11-15T07:27:05+00:00") assert(result.packets[0].rtt == 36.741) assert(result.packets[1].rtt == 36.66) assert(result.packets[2].rtt == 36.424) assert(result.packets[0].ttl is None) assert(result.packets[1].ttl is None) assert(result.packets[2].ttl is None) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address is None) assert(result.packets[1].source_address is None) assert(result.packets[2].source_address is None) def test_ping_4600(): result = Result.get('{"af":4,"avg":47.951999999999998,"dst_addr":"62.2.16.24","dst_name":"hsi.cablecom.ch","dup":0,"from":"188.195.183.141","fw":4600,"group_id":1000192,"lts":222,"max":48.990000000000002,"min":45.939,"msm_id":1000192,"msm_name":"Ping","prb_id":270,"proto":"ICMP","rcvd":3,"result":[{"rtt":45.939},{"rtt":48.927},{"rtt":48.990000000000002}],"sent":3,"size":12,"src_addr":"192.168.178.21","step":360,"timestamp":1392321470,"ttl":50,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 47.952) assert(result.rtt_median == 48.927) assert(result.destination_address == "62.2.16.24") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "188.195.183.141") assert(result.firmware == 4600) assert(result.seconds_since_sync == 222) assert(result.rtt_max == 48.99) assert(result.rtt_min == 45.939) assert(result.measurement_id == 1000192) assert(result.probe_id == 270) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step == 360) assert(result.created.isoformat() == "2014-02-13T19:57:50+00:00") assert(result.packets[0].rtt == 45.939) assert(result.packets[1].rtt == 48.927) assert(result.packets[2].rtt == 48.99) assert(result.packets[0].ttl == 50) assert(result.packets[1].ttl == 50) assert(result.packets[2].ttl == 50) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.178.21") assert(result.packets[1].source_address == "192.168.178.21") assert(result.packets[2].source_address == "192.168.178.21") def test_ping_4610(): result = Result.get('{"af":4,"avg":57.140666666666668,"dst_addr":"62.2.16.24","dst_name":"hsi.cablecom.ch","dup":0,"from":"188.195.181.120","fw":4610,"group_id":1000192,"lts":93,"max":63.213000000000001,"min":47.941000000000003,"msm_id":1000192,"msm_name":"Ping","prb_id":270,"proto":"ICMP","rcvd":3,"result":[{"rtt":63.213000000000001},{"rtt":47.941000000000003,"ttl":51},{"rtt":60.268000000000001,"ttl":50}],"sent":3,"size":12,"src_addr":"192.168.178.21","step":360,"timestamp":1395416383,"ttl":50,"type":"ping"}') assert(isinstance(result, Result)) assert(isinstance(result, PingResult)) assert(isinstance(result.packets[0], Packet)) assert(isinstance(result.packets[1], Packet)) assert(isinstance(result.packets[2], Packet)) assert(result.af == 4) assert(result.rtt_average == 57.141) assert(result.rtt_median == 60.268) assert(result.destination_address == "62.2.16.24") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 0) assert(result.origin == "188.195.181.120") assert(result.firmware == 4610) assert(result.seconds_since_sync == 93) assert(result.rtt_max == 63.213) assert(result.rtt_min == 47.941) assert(result.measurement_id == 1000192) assert(result.probe_id == 270) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 3) assert(result.packets_sent == 3) assert(result.packet_size == 12) assert(result.step == 360) assert(result.created.isoformat() == "2014-03-21T15:39:43+00:00") assert(result.packets[0].rtt == 63.213) assert(result.packets[1].rtt == 47.941) assert(result.packets[2].rtt == 60.268) assert(result.packets[0].ttl == 50) assert(result.packets[1].ttl == 51) assert(result.packets[2].ttl == 50) assert(result.packets[0].dup is False) assert(result.packets[1].dup is False) assert(result.packets[2].dup is False) assert(result.packets[0].source_address == "192.168.178.21") assert(result.packets[1].source_address == "192.168.178.21") assert(result.packets[2].source_address == "192.168.178.21") def test_ping_duplicate(): result = Result.get('{"af":4,"avg":27.768000000000001,"dst_addr":"62.2.16.24","dst_name":"hsi.cablecom.ch","dup":2,"from":"109.190.83.40","fw":4610,"lts":38,"max":27.768000000000001,"min":27.768000000000001,"msm_id":1000192,"msm_name":"Ping","prb_id":1216,"proto":"ICMP","rcvd":1,"result":[{"srcaddr":"192.168.103.130","x":"*"},{"dup":1,"rtt":36.454000000000001,"ttl":54},{"dup":1,"rtt":37.756},{"rtt":27.768000000000001}],"sent":2,"size":12,"src_addr":"192.168.103.130","step":360,"timestamp":1395277728,"ttl":54,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average == 27.768) assert(result.rtt_median == 27.768) assert(result.destination_address == "62.2.16.24") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 2) assert(result.origin == "109.190.83.40") assert(result.firmware == 4610) assert(result.seconds_since_sync == 38) assert(result.rtt_max == 27.768) assert(result.rtt_min == 27.768) assert(result.measurement_id == 1000192) assert(result.probe_id == 1216) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 1) assert(result.packets_sent == 2) assert(result.packet_size == 12) assert(result.step == 360) assert(result.created.isoformat() == "2014-03-20T01:08:48+00:00") assert(result.packets[0].rtt is None) assert(result.packets[1].rtt == 36.454) assert(result.packets[2].rtt == 37.756) assert(result.packets[3].rtt == 27.768) assert(result.packets[0].ttl is None) assert(result.packets[1].ttl == 54) assert(result.packets[2].ttl == 54) assert(result.packets[3].ttl == 54) assert(result.packets[0].dup is False) assert(result.packets[1].dup is True) assert(result.packets[2].dup is True) assert(result.packets[3].dup is False) assert(result.packets[0].source_address == "192.168.103.130") assert(result.packets[1].source_address == "192.168.103.130") assert(result.packets[2].source_address == "192.168.103.130") assert(result.packets[3].source_address == "192.168.103.130") def test_ping_buggy(): result = Result.get('{"af":4,"avg":-1,"dst_addr":"62.2.16.24","dst_name":"hsi.cablecom.ch","dup":2,"from":"62.195.143.53","fw":4600,"lts":130,"max":-1,"min":-1,"msm_id":1000192,"msm_name":"Ping","prb_id":202,"proto":"ICMP","rcvd":0,"result":[{"srcaddr":"192.168.1.229","x":"*"},{"dup":1,"rtt":1635.423,"ttl":55},{"dup":1,"rtt":1800.4939999999999}],"sent":1,"size":12,"src_addr":"192.168.1.229","step":360,"timestamp":1394745831,"ttl":55,"type":"ping"}') assert(result.af == 4) assert(result.rtt_average is None) assert(result.rtt_median is None) assert(result.destination_address == "62.2.16.24") assert(result.destination_name == "hsi.cablecom.ch") assert(result.duplicates == 2) assert(result.origin == "62.195.143.53") assert(result.firmware == 4600) assert(result.seconds_since_sync == 130) assert(result.rtt_max is None) assert(result.rtt_min is None) assert(result.measurement_id == 1000192) assert(result.probe_id == 202) assert(result.protocol == PingResult.PROTOCOL_ICMP) assert(result.packets_received == 0) assert(result.packets_sent == 1) assert(result.packet_size == 12) assert(result.step == 360) print(result.created, type(result.created)) print(result.created.isoformat()) assert(result.created.isoformat() == "2014-03-13T21:23:51+00:00") assert(result.packets[0].rtt is None) assert(result.packets[1].rtt == 1635.423) assert(result.packets[2].rtt == 1800.494) assert(result.packets[0].ttl is None) assert(result.packets[1].ttl == 55) assert(result.packets[2].ttl == 55) assert(result.packets[0].dup is False) assert(result.packets[1].dup is True) assert(result.packets[2].dup is True) assert(result.packets[0].source_address == "192.168.1.229") assert(result.packets[1].source_address == "192.168.1.229") assert(result.packets[2].source_address == "192.168.1.229") def test_ping_lts(): result = Result.get('{"af":4,"prb_id":270,"result":[{"rtt":70.265},{"rtt":54.584,"ttl":51},{"rtt":52.875}],"ttl":51,"avg":59.2413333333,"size":12,"from":"188.193.157.75","proto":"ICMP","timestamp":1406561624,"dup":0,"type":"ping","sent":3,"msm_id":1000192,"fw":4650,"max":70.265,"step":360,"src_addr":"192.168.178.21","rcvd":3,"msm_name":"Ping","lts":76,"dst_name":"hsi.cablecom.ch","min":52.875,"group_id":1000192,"dst_addr":"62.2.16.24"}') assert(result.seconds_since_sync == 76) ripe-atlas-sagan-1.3.1/tests/ssl.py000066400000000000000000002055141405365472700172050ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from ripe.atlas.sagan import Result, ResultError from ripe.atlas.sagan.ssl import SslResult def test_ssl_4480(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIFBTCCAu2gAwIBAgIDDLHHMA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTEzMDEwNjE0MDA1NVoXDTEzMDcwNTE0MDA1NVowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\\nAQoCggEBAMS+vX7gA8TvzFwxryFFRj1OyQjnW88GvfMuGhKJopalG1EB103oRsxi\\nMcXqwFZUicpqLKHW4lCHcRuhpKoZp8EOILnRAJRKFOjgIrcHQ02Xn4Lf/ewl601h\\n5qxqt1keU1P8j+u9m7zZN+vOoNlEKZ5SnZhysAAYqr/XIt1WY2cji/4GxjF+q1OH\\nIl5zddkIfnE52UbREKKlIakfFdj/c6GXqqsP2QTmm4x2HitCD964tZ06fA9BitQj\\nnnBXNhtm2MCuBIPBSq0/C7LREwmfnqxCFqE7iqEPNIQ2IT2D4Gh4c+nIZHqYKvCV\\nP3zh3aUaBj1o5Lo83IDdXCKAIiQRFMkCAwEAAaOB9jCB8zAMBgNVHRMBAf8EAjAA\\nMA4GA1UdDwEB/wQEAwIDqDA0BgNVHSUELTArBggrBgEFBQcDAgYIKwYBBQUHAwEG\\nCWCGSAGG+EIEAQYKKwYBBAGCNwoDAzAzBggrBgEFBQcBAQQnMCUwIwYIKwYBBQUH\\nMAGGF2h0dHA6Ly9vY3NwLmNhY2VydC5vcmcvMDEGA1UdHwQqMCgwJqAkoCKGIGh0\\ndHA6Ly9jcmwuY2FjZXJ0Lm9yZy9yZXZva2UuY3JsMDUGA1UdEQQuMCyCDSoucHJl\\ndGljYWwuZWWgGwYIKwYBBQUHCAWgDwwNKi5wcmV0aWNhbC5lZTANBgkqhkiG9w0B\\nAQUFAAOCAgEAycddS/c47eo0WVrFxpvCIJdfvn7CYdTPpXNSg0kjapkSjYuAkcmq\\nsrScUUGMBe6tfkmkdPTuNKwRVYNJ1Wi9EYaMvJ3CVw6x9O5mgktmu0ogbIXsivwI\\nTSzGDMWcb9Of85e/ALWpK0cWIugtWO0d6v3qMWfxlYfAaYu49pttOJQOjbXAAhfR\\njE5VOcDaIlWChG48jLAyCLsMwHlyLw8D5Myb9MfTs1XxgLESO9ZTSqGEqJw+BwTJ\\nstHk/oCHo9FL/Xv5MmFcNaTpqbB60duYJ+DLLX1QiRRfLJ18G7wEiEAm6H9egupQ\\nL9MhQQLJ4o60xTrCnpqGTXTSR16jiTm70bDB0+SU3xTpNwCzdigH6ceKbPIr0cO6\\no0ump598e2JNCPsXIc+XcbLDDFgYrlnl3YnK3J+K3LC7SWPMsYdDfe+Im880tNuW\\nOlnOCDpP8408KqCp4xm0DMznmThUM34/Ia+o8Q3NWNBfuaOsJ9aA+FmgobJhih9e\\nUr9x3ByRQXcW5Cs/AMtCikKWVPsx+IA5eeyt+1i+dKBWksO40B3ADsq1O5DRYYRa\\n+dwqdX/jduqZjbyHuFH04q28j4zVDviUBQEa9UQoDM3c82dILDjbYtZ+T28sPMTa\\nbMZdcMur9E+ovrS58lIKGCvDEPSUDXHzr0tpb4A13TTnxW6pclqUyJk=\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"https","from":"77.95.64.18","fw":4480,"method":"SSL","msm_id":1006864,"prb_id":517,"src_addr":"77.95.64.18","timestamp":1362454627,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4480) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "77.95.64.18") assert(result.port == 443) assert(result.origin == "77.95.64.18") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time is None) assert(result.time_to_connect is None) assert(result.measurement_id == 1006864) assert(result.probe_id == 517) assert(result.created.isoformat() == "2013-03-05T03:37:07+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2013-01-06T14:00:55+00:00") assert(result.certificates[0].valid_until.isoformat() == "2013-07-05T14:00:55+00:00") assert(result.certificates[0].checksum == "AC:D1:6F:FB:3A:F2:06:C9:92:A4:4D:2A:A2:0B:1C:37:35:25:75:A7:5D:4A:62:21:03:AD:E6:46:42:E5:65:4C") assert(result.certificates[0].checksum_md5 == "91:EA:DF:FF:57:6F:7C:91:F1:83:2A:9F:7F:A2:FE:E4") assert(result.certificates[0].checksum_sha1 == "11:00:27:07:F7:E8:0C:6B:5F:B6:A3:5A:20:19:BC:CA:22:85:E5:3C") assert(result.certificates[0].checksum_sha256 == "AC:D1:6F:FB:3A:F2:06:C9:92:A4:4D:2A:A2:0B:1C:37:35:25:75:A7:5D:4A:62:21:03:AD:E6:46:42:E5:65:4C") def test_ssl_4500(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIFBTCCAu2gAwIBAgIDDLHHMA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ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ogbIXsivwI\\nTSzGDMWcb9Of85e/ALWpK0cWIugtWO0d6v3qMWfxlYfAaYu49pttOJQOjbXAAhfR\\njE5VOcDaIlWChG48jLAyCLsMwHlyLw8D5Myb9MfTs1XxgLESO9ZTSqGEqJw+BwTJ\\nstHk/oCHo9FL/Xv5MmFcNaTpqbB60duYJ+DLLX1QiRRfLJ18G7wEiEAm6H9egupQ\\nL9MhQQLJ4o60xTrCnpqGTXTSR16jiTm70bDB0+SU3xTpNwCzdigH6ceKbPIr0cO6\\no0ump598e2JNCPsXIc+XcbLDDFgYrlnl3YnK3J+K3LC7SWPMsYdDfe+Im880tNuW\\nOlnOCDpP8408KqCp4xm0DMznmThUM34/Ia+o8Q3NWNBfuaOsJ9aA+FmgobJhih9e\\nUr9x3ByRQXcW5Cs/AMtCikKWVPsx+IA5eeyt+1i+dKBWksO40B3ADsq1O5DRYYRa\\n+dwqdX/jduqZjbyHuFH04q28j4zVDviUBQEa9UQoDM3c82dILDjbYtZ+T28sPMTa\\nbMZdcMur9E+ovrS58lIKGCvDEPSUDXHzr0tpb4A13TTnxW6pclqUyJk=\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"https","from":"77.95.64.18","fw":4500,"method":"SSL","msm_id":1006864,"prb_id":517,"src_addr":"77.95.64.18","timestamp":1365577623,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4500) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "77.95.64.18") assert(result.port == 443) assert(result.origin == "77.95.64.18") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time is None) assert(result.time_to_connect is None) assert(result.measurement_id == 1006864) assert(result.probe_id == 517) assert(result.created.isoformat() == "2013-04-10T07:07:03+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2013-01-06T14:00:55+00:00") assert(result.certificates[0].valid_until.isoformat() == "2013-07-05T14:00:55+00:00") assert(result.certificates[0].checksum == "AC:D1:6F:FB:3A:F2:06:C9:92:A4:4D:2A:A2:0B:1C:37:35:25:75:A7:5D:4A:62:21:03:AD:E6:46:42:E5:65:4C") assert(result.certificates[0].checksum_md5 == "91:EA:DF:FF:57:6F:7C:91:F1:83:2A:9F:7F:A2:FE:E4") assert(result.certificates[0].checksum_sha1 == "11:00:27:07:F7:E8:0C:6B:5F:B6:A3:5A:20:19:BC:CA:22:85:E5:3C") assert(result.certificates[0].checksum_sha256 == "AC:D1:6F:FB:3A:F2:06:C9:92:A4:4D:2A:A2:0B:1C:37:35:25:75:A7:5D:4A:62:21:03:AD:E6:46:42:E5:65:4C") def test_ssl_4520(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDXW/MA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTEzMDcwNjA1NTQ1NFoXDTE0MDEwMjA1NTQ1NFowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\\nAQoCggEBAMS+vX7gA8TvzFwxryFFRj1OyQjnW88GvfMuGhKJopalG1EB103oRsxi\\nMcXqwFZUicpqLKHW4lCHcRuhpKoZp8EOILnRAJRKFOjgIrcHQ02Xn4Lf/ewl601h\\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ar5p69yJG\\n9aMR6bjnmtTnhCigtOj7L/IpKV1b1/+nK5+00wJEF6mIvtMCMr+7zf62LTLRgM8U\\njzPNkFt0hzq3coOKOeho6pGvE9NyV+8Ed7K9H3DpYf4y5BDigOGfLVU9bnYaJdWn\\ngRkq8Xmcm73lglN49oBXrxZrxQh0LAHWgbNxuQ3iMAvmuw==\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"https","from":"77.95.64.18","fw":4520,"method":"SSL","msm_id":1006864,"msm_name":"SSLCert","prb_id":517,"src_addr":"77.95.64.18","timestamp":1378499876,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4520) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "77.95.64.18") assert(result.port == 443) assert(result.origin == "77.95.64.18") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time is None) assert(result.time_to_connect is None) assert(result.measurement_id == 1006864) assert(result.probe_id == 517) assert(result.created.isoformat() == "2013-09-06T20:37:56+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2013-07-06T05:54:54+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-01-02T05:54:54+00:00") assert(result.certificates[0].checksum == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") assert(result.certificates[0].checksum_md5 == "38:07:D1:3C:0C:79:01:5E:F6:0E:6B:48:B4:3C:F4:59") assert(result.certificates[0].checksum_sha1 == "C5:31:2B:AC:B2:4F:D2:F8:47:57:2A:4F:04:D7:F9:18:91:20:C7:1F") assert(result.certificates[0].checksum_sha256 == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") def test_ssl_4540(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDXW/MA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTEzMDcwNjA1NTQ1NFoXDTE0MDEwMjA1NTQ1NFowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\\nAQoCggEBAMS+vX7gA8TvzFwxryFFRj1OyQjnW88GvfMuGhKJopalG1EB103oRsxi\\nMcXqwFZUicpqLKHW4lCHcRuhpKoZp8EOILnRAJRKFOjgIrcHQ02Xn4Lf/ewl601h\\n5qxqt1keU1P8j+u9m7zZN+vOoNlEKZ5SnZhysAAYqr/XIt1WY2cji/4GxjF+q1OH\\nIl5zddkIfnE52UbREKKlIakfFdj/c6GXqqsP2QTmm4x2HitCD964tZ06fA9BitQj\\nnnBXNhtm2MCuBIPBSq0/C7LREwmfnqxCFqE7iqEPNIQ2IT2D4Gh4c+nIZHqYKvCV\\nP3zh3aUaBj1o5Lo83IDdXCKAIiQRFMkCAwEAAaOBvzCBvDAMBgNVHRMBAf8EAjAA\\nMA4GA1UdDwEB/wQEAwIDqDA0BgNVHSUELTArBggrBgEFBQcDAgYIKwYBBQUHAwEG\\nCWCGSAGG+EIEAQYKKwYBBAGCNwoDAzAzBggrBgEFBQcBAQQnMCUwIwYIKwYBBQUH\\nMAGGF2h0dHA6Ly9vY3NwLmNhY2VydC5vcmcvMDEGA1UdHwQqMCgwJqAkoCKGIGh0\\ndHA6Ly9jcmwuY2FjZXJ0Lm9yZy9yZXZva2UuY3JsMA0GCSqGSIb3DQEBBQUAA4IC\\nAQA3/H0E30Ukgu+icBzxOIduVai4GMrNEved6P4toz7ZjzRXv4OczpIB8KSPS9S2\\nv3EiL/YSymH9a+GrfuyZ83WqL8xNUEbCy8bkMimR0zL03dmQIM+9lCjofk80dl2l\\nqhcvjk7H6nWyVJKxVN61+XiGCznhvqZJyAZLOFNaXqyryOLmnzPMM/a6kFOijU/m\\nnhXrz56DVSYYbJVaTkJMFwNSQST+bJXz2OCWO3ovMd6iP13/w3/XL/L+p6p1wFOx\\nYPa3j6pz0zeFYH4U4xlg95MtuMwMDxJtJBPavBotpKFHT89C2Da/mxgiJalmpcnh\\nxFFRrbvkIc3oL2rW/+ZDhQpHbvMAXIhBnrBdTduSbargHaCm24Ga/R/JIxZJHP65\\n2m17gtBbqijy+4fNxQE67+cWNS3k56LyXzW2Cm1Mvz9p8IjZFalO6zf45n55f5xE\\nkK/kM2zZ5ZXJ28Y2wZ/nGABAqvQsbcd6/XtoTwcxt+GUQoCQ3AT2RR9Ar5p69yJG\\n9aMR6bjnmtTnhCigtOj7L/IpKV1b1/+nK5+00wJEF6mIvtMCMr+7zf62LTLRgM8U\\njzPNkFt0hzq3coOKOeho6pGvE9NyV+8Ed7K9H3DpYf4y5BDigOGfLVU9bnYaJdWn\\ngRkq8Xmcm73lglN49oBXrxZrxQh0LAHWgbNxuQ3iMAvmuw==\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"443","from":"82.161.40.58","fw":4540,"method":"SSL","msm_id":1006864,"msm_name":"SSLCert","prb_id":12,"rt":119.526,"src_addr":"192.168.178.250","timestamp":1377694418,"ttc":57.616999999999997,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4540) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "192.168.178.250") assert(result.port == 443) assert(result.origin == "82.161.40.58") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time == 119.526) assert(result.time_to_connect == 57.617) assert(result.measurement_id == 1006864) assert(result.probe_id == 12) assert(result.created.isoformat() == "2013-08-28T12:53:38+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2013-07-06T05:54:54+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-01-02T05:54:54+00:00") assert(result.certificates[0].checksum == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") assert(result.certificates[0].checksum_md5 == "38:07:D1:3C:0C:79:01:5E:F6:0E:6B:48:B4:3C:F4:59") assert(result.certificates[0].checksum_sha1 == "C5:31:2B:AC:B2:4F:D2:F8:47:57:2A:4F:04:D7:F9:18:91:20:C7:1F") assert(result.certificates[0].checksum_sha256 == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") def test_ssl_4550(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDXW/MA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\n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ijU/m\\nnhXrz56DVSYYbJVaTkJMFwNSQST+bJXz2OCWO3ovMd6iP13/w3/XL/L+p6p1wFOx\\nYPa3j6pz0zeFYH4U4xlg95MtuMwMDxJtJBPavBotpKFHT89C2Da/mxgiJalmpcnh\\nxFFRrbvkIc3oL2rW/+ZDhQpHbvMAXIhBnrBdTduSbargHaCm24Ga/R/JIxZJHP65\\n2m17gtBbqijy+4fNxQE67+cWNS3k56LyXzW2Cm1Mvz9p8IjZFalO6zf45n55f5xE\\nkK/kM2zZ5ZXJ28Y2wZ/nGABAqvQsbcd6/XtoTwcxt+GUQoCQ3AT2RR9Ar5p69yJG\\n9aMR6bjnmtTnhCigtOj7L/IpKV1b1/+nK5+00wJEF6mIvtMCMr+7zf62LTLRgM8U\\njzPNkFt0hzq3coOKOeho6pGvE9NyV+8Ed7K9H3DpYf4y5BDigOGfLVU9bnYaJdWn\\ngRkq8Xmcm73lglN49oBXrxZrxQh0LAHWgbNxuQ3iMAvmuw==\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"443","from":"118.209.21.239","fw":4550,"method":"SSL","msm_id":1006864,"msm_name":"SSLCert","prb_id":33,"rt":703.38599999999997,"src_addr":"192.168.178.29","timestamp":1378042943,"ttc":349.20499999999998,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4550) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "192.168.178.29") assert(result.port == 443) assert(result.origin == "118.209.21.239") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time == 703.386) assert(result.time_to_connect == 349.205) assert(result.measurement_id == 1006864) assert(result.probe_id == 33) assert(result.created.isoformat() == "2013-09-01T13:42:23+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2013-07-06T05:54:54+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-01-02T05:54:54+00:00") assert(result.certificates[0].checksum == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") assert(result.certificates[0].checksum_md5 == "38:07:D1:3C:0C:79:01:5E:F6:0E:6B:48:B4:3C:F4:59") assert(result.certificates[0].checksum_sha1 == "C5:31:2B:AC:B2:4F:D2:F8:47:57:2A:4F:04:D7:F9:18:91:20:C7:1F") assert(result.certificates[0].checksum_sha256 == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") def test_ssl_4550_error(): result_string = '{"dnserr":"non-recoverable failure in name resolution","dst_name":"pretical.ee","dst_port":"443","from":"77.95.64.18","fw":4550,"msm_id":1006864,"msm_name":"SSLCert","prb_id":517,"timestamp":1380791230,"type":"sslcert"}' result = Result.get(result_string) assert(isinstance(result, SslResult)) assert(result.af is None) assert(result.firmware == 4550) assert(result.destination_address is None) assert(result.destination_name == "pretical.ee") assert(result.source_address is None) assert(result.port == 443) assert(result.origin == "77.95.64.18") assert(result.method is None) assert(result.version is None) assert(result.response_time is None) assert(result.time_to_connect is None) assert(result.measurement_id == 1006864) assert(result.probe_id == 517) assert(result.created.isoformat() == "2013-10-03T09:07:10+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 0) assert(result.is_error is True) try: Result.get(result_string, on_error=Result.ACTION_FAIL) assert False except ResultError: pass def test_ssl_4560(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDXW/MA0GCSqGSIb3DQEBBQ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WqL8xNUEbCy8bkMimR0zL03dmQIM+9lCjofk80dl2l\\nqhcvjk7H6nWyVJKxVN61+XiGCznhvqZJyAZLOFNaXqyryOLmnzPMM/a6kFOijU/m\\nnhXrz56DVSYYbJVaTkJMFwNSQST+bJXz2OCWO3ovMd6iP13/w3/XL/L+p6p1wFOx\\nYPa3j6pz0zeFYH4U4xlg95MtuMwMDxJtJBPavBotpKFHT89C2Da/mxgiJalmpcnh\\nxFFRrbvkIc3oL2rW/+ZDhQpHbvMAXIhBnrBdTduSbargHaCm24Ga/R/JIxZJHP65\\n2m17gtBbqijy+4fNxQE67+cWNS3k56LyXzW2Cm1Mvz9p8IjZFalO6zf45n55f5xE\\nkK/kM2zZ5ZXJ28Y2wZ/nGABAqvQsbcd6/XtoTwcxt+GUQoCQ3AT2RR9Ar5p69yJG\\n9aMR6bjnmtTnhCigtOj7L/IpKV1b1/+nK5+00wJEF6mIvtMCMr+7zf62LTLRgM8U\\njzPNkFt0hzq3coOKOeho6pGvE9NyV+8Ed7K9H3DpYf4y5BDigOGfLVU9bnYaJdWn\\ngRkq8Xmcm73lglN49oBXrxZrxQh0LAHWgbNxuQ3iMAvmuw==\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"443","from":"62.146.75.210","fw":4560,"method":"SSL","msm_id":1006864,"msm_name":"SSLCert","prb_id":259,"rt":71.572999999999993,"src_addr":"10.0.9.74","timestamp":1385719912,"ttc":33.630000000000003,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4560) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "10.0.9.74") assert(result.port == 443) assert(result.origin == "62.146.75.210") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time == 71.573) assert(result.time_to_connect == 33.63) assert(result.measurement_id == 1006864) assert(result.probe_id == 259) assert(result.created.isoformat() == "2013-11-29T10:11:52+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2013-07-06T05:54:54+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-01-02T05:54:54+00:00") assert(result.certificates[0].checksum == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") assert(result.certificates[0].checksum_md5 == "38:07:D1:3C:0C:79:01:5E:F6:0E:6B:48:B4:3C:F4:59") assert(result.certificates[0].checksum_sha1 == "C5:31:2B:AC:B2:4F:D2:F8:47:57:2A:4F:04:D7:F9:18:91:20:C7:1F") assert(result.certificates[0].checksum_sha256 == "F9:C1:DC:CE:CE:C2:E8:42:00:D1:A1:B5:0D:93:09:DE:73:DA:CE:56:0A:FD:A3:BB:B1:CC:1E:2E:47:15:C3:A6") def test_ssl_4570(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDky9MA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTE0MDEwMzIxMjI1MVoXDTE0MDcwMjIxMjI1MVowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\\nAQoCggEBAMS+vX7gA8TvzFwxryFFRj1OyQjnW88GvfMuGhKJop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yQ4AV4ga4SM5BZksbsfXgEgXyxdo8DN\\nZO4PfRAtaSH+ZKrmgmrcm/CcvNn+EaW6qw7dAhJE4JNkfUAm5qMTuA35ERMkgucD\\nyu/PjjzBG2HeHrSqzb3ZoERlF8wfU0wIJeiDRtHYUfu/Hr+XA/80Uq66YrhRyqPS\\nM1x0SqeaCYdgfsmK1fB0/brDbOhNXIYbvIShcimGyjfKyHK/FL18SF676/Mc9fbe\\ngWyIey4h+S/dYCHJpVKj2HUq1Jni6n3CtxNyqF0EjR1FVA==\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"443","from":"31.24.127.132","fw":4570,"method":"SSL","msm_id":1006864,"msm_name":"SSLCert","prb_id":417,"rt":149.22300000000001,"src_addr":"31.24.127.132","timestamp":1392657784,"ttc":72.516000000000005,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4570) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "31.24.127.132") assert(result.port == 443) assert(result.origin == "31.24.127.132") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time == 149.223) assert(result.time_to_connect == 72.516) assert(result.measurement_id == 1006864) assert(result.probe_id == 417) assert(result.created.isoformat() == "2014-02-17T17:23:04+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2014-01-03T21:22:51+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-07-02T21:22:51+00:00") assert(result.certificates[0].checksum == "28:E6:A2:51:CE:D1:E9:34:2E:69:41:44:55:43:41:88:4D:93:4E:67:02:09:48:8C:86:68:25:8F:5E:DF:96:98") assert(result.certificates[0].checksum_md5 == "97:A2:0C:C7:93:E1:4B:24:6D:EA:55:09:6E:21:A8:96") assert(result.certificates[0].checksum_sha1 == "2B:FE:E8:F8:4B:25:19:D4:9B:3B:18:A3:29:E1:6C:79:72:FF:96:02") assert(result.certificates[0].checksum_sha256 == "28:E6:A2:51:CE:D1:E9:34:2E:69:41:44:55:43:41:88:4D:93:4E:67:02:09:48:8C:86:68:25:8F:5E:DF:96:98") def test_ssl_4600(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDky9MA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTE0MDEwMzIxMjI1MVoXDTE0MDcwMjIxMjI1MVowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\\nAQoCggEBAMS+vX7gA8TvzFwxryFFRj1OyQjnW88GvfMuGhKJopalG1EB103oRsxi\\nMcXqwFZUicpqLKHW4lCHcRuhpKoZp8EOILnRAJRKFOjgIrcHQ02Xn4Lf/ewl601h\\n5qxqt1keU1P8j+u9m7zZN+vOoNlEKZ5SnZhysAAYqr/XIt1WY2cji/4GxjF+q1OH\\nIl5zddkIfnE52UbREKKlIakfFdj/c6GXqqsP2QTmm4x2HitCD964tZ06fA9BitQj\\nnnBXNhtm2MCuBIPBSq0/C7LREwmfnqxCFqE7iqEPNIQ2IT2D4Gh4c+nIZHqYKvCV\\nP3zh3aUaBj1o5Lo83IDdXCKAIiQRFMkCAwEAAaOBvzCBvDAMBgNVHRMBAf8EAjAA\\nMA4GA1UdDwEB/w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SL","msm_id":1006864,"msm_name":"SSLCert","prb_id":417,"rt":146.65700000000001,"src_addr":"31.24.127.132","timestamp":1395807798,"ttc":71.251000000000005,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4600) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "31.24.127.132") assert(result.port == 443) assert(result.origin == "31.24.127.132") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time == 146.657) assert(result.time_to_connect == 71.251) assert(result.measurement_id == 1006864) assert(result.probe_id == 417) assert(result.created.isoformat() == "2014-03-26T04:23:18+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2014-01-03T21:22:51+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-07-02T21:22:51+00:00") assert(result.certificates[0].checksum == "28:E6:A2:51:CE:D1:E9:34:2E:69:41:44:55:43:41:88:4D:93:4E:67:02:09:48:8C:86:68:25:8F:5E:DF:96:98") assert(result.certificates[0].checksum_md5 == "97:A2:0C:C7:93:E1:4B:24:6D:EA:55:09:6E:21:A8:96") assert(result.certificates[0].checksum_sha1 == "2B:FE:E8:F8:4B:25:19:D4:9B:3B:18:A3:29:E1:6C:79:72:FF:96:02") assert(result.certificates[0].checksum_sha256 == "28:E6:A2:51:CE:D1:E9:34:2E:69:41:44:55:43:41:88:4D:93:4E:67:02:09:48:8C:86:68:25:8F:5E:DF:96:98") def test_ssl_4610(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIEzjCCAragAwIBAgIDDky9MA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBA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kbJCG1Wnwku2CqIPvRwrazmd0IAOZ\\nXO3kymgbo+pmARWIulpbxz5wzCG0K5OFSFO0Ow4p4MqdrGcid9tZ81Z+db7PbVkk\\nGAwlJya0Y8kRZS/arG+UPCPl+O2OV6ICmZ3502+nJJhZ1Ahx7stjtv69HxWoX3zQ\\n/xuBnKFIZK1EtlVKVvXcFth7akRqs0K9/h1kaxoKoPBfxpZqhjOiu6+OkdydP+CY\\nkRZsj2WDYqZlbSnzYNsqy1Asp/cfsyWHp+scUBh+f4ENDg98M9sl4tpOATH+OFD7\\nypdttWGjShYfOeQWWJF9J9Q/YFseYH1oAyQ4AV4ga4SM5BZksbsfXgEgXyxdo8DN\\nZO4PfRAtaSH+ZKrmgmrcm/CcvNn+EaW6qw7dAhJE4JNkfUAm5qMTuA35ERMkgucD\\nyu/PjjzBG2HeHrSqzb3ZoERlF8wfU0wIJeiDRtHYUfu/Hr+XA/80Uq66YrhRyqPS\\nM1x0SqeaCYdgfsmK1fB0/brDbOhNXIYbvIShcimGyjfKyHK/FL18SF676/Mc9fbe\\ngWyIey4h+S/dYCHJpVKj2HUq1Jni6n3CtxNyqF0EjR1FVA==\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"443","from":"125.238.215.240","fw":4610,"method":"SSL","msm_id":1006864,"msm_name":"SSLCert","prb_id":74,"rt":696.07500000000005,"src_addr":"10.0.0.2","timestamp":1396269382,"ttc":345.97899999999998,"type":"sslcert","ver":"3.0"}') assert(isinstance(result, SslResult)) assert(result.af == 4) assert(result.firmware == 4610) assert(result.destination_address == "80.79.115.54") assert(result.destination_name == "pretical.ee") assert(result.source_address == "10.0.0.2") assert(result.port == 443) assert(result.origin == "125.238.215.240") assert(result.method == "SSL") assert(result.version == "3.0") assert(result.response_time == 696.075) assert(result.time_to_connect == 345.979) assert(result.measurement_id == 1006864) assert(result.probe_id == 74) assert(result.created.isoformat() == "2014-03-31T12:36:22+00:00") assert(isinstance(result.certificates, list)) assert(len(result.certificates) == 1) assert(result.certificates[0]) assert(result.certificates[0].subject_cn == "*.pretical.ee") assert(result.certificates[0].subject_o is None) assert(result.certificates[0].subject_c is None) assert(result.certificates[0].issuer_cn == "CA Cert Signing Authority") assert(result.certificates[0].issuer_o == "Root CA") assert(result.certificates[0].issuer_c is None) assert(result.certificates[0].valid_from.isoformat() == "2014-01-03T21:22:51+00:00") assert(result.certificates[0].valid_until.isoformat() == "2014-07-02T21:22:51+00:00") assert(result.certificates[0].checksum == "28:E6:A2:51:CE:D1:E9:34:2E:69:41:44:55:43:41:88:4D:93:4E:67:02:09:48:8C:86:68:25:8F:5E:DF:96:98") assert(result.certificates[0].checksum_md5 == "97:A2:0C:C7:93:E1:4B:24:6D:EA:55:09:6E:21:A8:96") assert(result.certificates[0].checksum_sha1 == "2B:FE:E8:F8:4B:25:19:D4:9B:3B:18:A3:29:E1:6C:79:72:FF:96:02") assert(result.certificates[0].checksum_sha256 == "28:E6:A2:51:CE:D1:E9:34:2E:69:41:44:55:43:41:88:4D:93:4E:67:02:09:48:8C:86:68:25:8F:5E:DF:96:98") def test_ssl_lts(): result = Result.get('{"lts":143,"rt":149.405,"from":"94.214.66.164","dst_name":"pretical.ee","af":4,"timestamp":1406561035,"msm_name":"SSLCert","fw":4650,"prb_id":7,"method":"SSL","cert":["-----BEGIN CERTIFICATE-----\\nMIIFBTCCAu2gAwIBAgIDDzuhMA0GCSqGSIb3DQEBCwUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTE0MDcwMzE5MDczMVoXDTE0MTIzMDE5MDczMVowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEP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rYISmrksnTSYSp6xsEDWS5R\\nn3gP8\/PQVapttauTZ5vw3U8JEoo9Sa7U5O5M5TYgx9W8S0BU\/z6CQCltds3EdqxL\\n6YfEjORQ9Y6m8leyhp8muLCCGuo0J9icw0Y7Bz8WKx6RLZ6Sjq2Ezf9S6qfnKKPy\\nV2mY9JvBXTUsOGkPfIt0jN7EspLGM4Vx4UPxtMDeCnjUNzc76Xp\/HiEPFb2Iigaa\\nvOhLYPCI\/JiY06epFg3+Dsw4TW0LYVkHmTgAATw2xxPFMlL3gcebVCuxxog2+Ih9\\nwVg5K5hMwG+R6zvr+2WDcebpdFSTscibHywyey7tJUHNHRVi+8rnWxZjaQCwKGCE\\nVp6CMVtl39lL+MKzqJaeUORvMil8ye8jmOH4q7489t8QCJY9VN1S2tA=\\n-----END CERTIFICATE-----"],"dst_port":"443","ttc":94.057,"src_addr":"10.71.1.151","group_id":1006864,"type":"sslcert","dst_addr":"80.79.115.54","ver":"3.0","msm_id":1006864}') assert(result.seconds_since_sync == 143) def test_self_signed(): ca_signed = Result.get('{"lts":663,"rt":27.807,"from":"2001:67c:2e8:13:220:4aff:fec6:cc6e","dst_name":"2a00:1450:4005:809::1010","af":6,"timestamp":1410867341,"msm_name":"SSLCert","fw":4660,"prb_id":15,"method":"SSL","cert":["-----BEGIN CERTIFICATE-----\\nMIIEdjCCA16gAwIBAgIIcPRu2ubZ1kMwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE\\nBhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl\\ncm5ldCBBdXRob3JpdHkgRzIwHhcNMTQwODI3MTE0MDU1WhcNMTQxMTI1MDAwMDAw\\nWjBoMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN\\nTW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEXMBUGA1UEAwwOd3d3\\nLmdvb2dsZS5jb20wgg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iLnTjoBbdqfnGk5sRgprDvgOSJKA+eJdbtg\/OtppHHmMlCGDUUna2YRpIu\\nT8rxh0PBFpVXLVDviS2Aelet8u5fa9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6c\\nJmTM386DGXHKTubU1XupGc1V3sjs0l44U+VcT4wt\/lAjNvxm5suOpDkZALeVAjmR\\nCw7+OC7RHQWa9k0+bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5asz\\nPeE4uwc2hGKceeoWMPRfwCvocWvk+QIDAQABo4HwMIHtMB8GA1UdIwQYMBaAFEjm\\naPkr0rKV10fYIyAQTzOYkJ\/UMB0GA1UdDgQWBBTAephojYn7qwVkDBF9qn1luMrM\\nTjAPBgNVHRMBAf8EBTADAQH\/MA4GA1UdDwEB\/wQEAwIBBjA6BgNVHR8EMzAxMC+g\\nLaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDBO\\nBgNVHSAERzBFMEMGBFUdIAAwOzA5BggrBgEFBQcCARYtaHR0cHM6Ly93d3cuZ2Vv\\ndHJ1c3QuY29tL3Jlc291cmNlcy9yZXBvc2l0b3J5MA0GCSqGSIb3DQEBBQUAA4GB\\nAHbhEm5OSxYShjAGsoEIz\/AIx8dxfmbuwu3UOx\/\/8PDITtZDOLC5MH0Y0FWDomrL\\nNhGc6Ehmo21\/uBPUR\/6LWlxz\/K7ZGzIZOKuXNBSqltLroxwUCEm2u+WR74M26x1W\\nb8ravHNjkOR\/ez4iyz0H7V84dJzjA1BOoa+Y7mHyhD8S\\n-----END CERTIFICATE-----"],"dst_port":"443","ttc":11.956,"src_addr":"2001:67c:2e8:13:220:4aff:fec6:cc6e","group_id":1012449,"type":"sslcert","dst_addr":"2a00:1450:4005:809::1010","ver":"3.0","msm_id":1012449}') self_signed = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIDEDCCAfgCCQCKlfFLvltvwjANBgkqhkiG9w0BAQUFAD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ATE-----"],"dst_addr":"85.10.198.82","dst_name":"85.10.198.82","dst_port":"443","from":"109.201.224.30","fw":4660,"group_id":1766133,"lts":178,"method":"SSL","msm_id":1766133,"msm_name":"SSLCert","prb_id":2965,"rt":3103.552,"src_addr":"10.119.35.124","timestamp":1410960180,"ttc":3046.154,"type":"sslcert","ver":"3.0"}') assert(ca_signed.is_self_signed == False) assert(self_signed.is_self_signed == True) def test_non_ascii(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\nMIIGRTCCBS2gAwIBAgIRANOWS9WhQ5qPpLm5lNqj+s8wDQYJKoZIhvcNAQELBQAw\ngc0xCzAJBgNVBAYTAlJVMQ8wDQYDVQQIEwZNb3Njb3cxDzANBgNVBAcTBk1vc2Nv\ndzFrMGkGA1UECgxiUlUtQ2VudGVyICjQl9CQ0J4g0KDQtdCz0LjQvtC90LDQu9GM\n0L3Ri9C5INCh0LXRgtC10LLQvtC5INCY0L3RhNC+0YDQvNCw0YbQuNC+0L3QvdGL\n0Lkg0KbQtdC90YLRgCkxLzAtBgNVBAMTJlJVLUNFTlRFUiBIaWdoIEFzc3VyYW5j\nZSBTZXJ2aWNlcyBDQSAyMB4XDTE1MDMyNjAwMDAwMFoXDTE3MDQwNjIzNTk1OVow\nggEiMQswCQYDVQQGEwJSVTEPMA0GA1UEERMGMTE3MTA1MQ8wDQYDVQQIEwZNb3Nj\nb3cxHTAbBgNVBAkTFFdhcnNoYXcgSGlnaHdheSA5IDFCMRUwEwYDVQQKEwxMTEMg\nS1VQSVNIVVoxFjAUBgNVBAsTDUlUIERlcGFydG1lbnQxbzBtBgNVBAsMZkhvc3Rl\nZCBieSBSVS1DZW50ZXIgKNCX0JDQniAi0KDQtdCz0LjQvtC90LDQu9GM0L3Ri9C5\nINCh0LXRgtC10LLQvtC5INCY0L3RhNC+0YDQvNCw0YbQuNC+0L3QvdGL0Lkg0KbQ\ntTEcMBoGA1UECxMTUHJlbWl1bVNTTCBXaWxkY2FyZDEUMBIGA1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oJ8OkLJvHgwmp1ocd5yblSYMgpEg7wrQPWCcR23+WmgZWn\nRtqCV6mVksW2jwMibDN3wXsyF24HzloUQToFJBv2FAY7qCUkDrvMKnXduXBBP3zQ\nYzYhBx9G/2CkkeFnvN4ffhkUyWNnkepnB2u0j4vAbkN9w6GAbLIevFOFfdyQoaS8\nLe9Gclc1Bb+7RrtubTeZtv8jkpHGbkD4jylW6l/VXxRTrPBPYer3IsynVgviuDQf\nJtl7GQVoP7o81DgGotPmjw7jtHFtQELFhLRAlSv0ZaBIefYdgWOWnU914Ph85I6p\n0fKtirOMxyHNwu8=\n-----END CERTIFICATE-----"],"dst_addr":"178.248.232.33","dst_name":"www.lamoda.ru","dst_port":"443","from":"84.248.94.134","fw":4700,"group_id":2198464,"lts":27,"method":"TLS","msm_id":2198464,"msm_name":"SSLCert","prb_id":20782,"rt":60.96,"src_addr":"192.168.1.191","timestamp":1438122124,"ttc":26.34,"type":"sslcert","ver":"1.2"}') assert(isinstance(result, SslResult)) def test_alert(): result = Result.get('{"lts":60,"rt":65.88887,"from":"134.197.42.163","dst_name":"aus5.mozilla.org","af":4,"timestamp":1452783251,"msm_name":"SSLCert","fw":4720,"alert":{"decription":40,"level":2},"method":"TLS","prb_id":10008,"dst_port":"443","ttc":31.621485,"src_addr":"134.197.42.163","group_id":3322890,"type":"sslcert","dst_addr":"63.245.213.47","ver":"1.2","msm_id":3322890}') assert(result.alert is not None) assert(result.alert.level == 2) assert(result.alert.description == 40) assert(result.alert.description_string == "handshake_failure") assert(result.is_error is True) assert(result.error_message == "handshake_failure") result = Result.get('{"lts":60,"rt":65.88887,"from":"134.197.42.163","dst_name":"aus5.mozilla.org","af":4,"timestamp":1452783251,"msm_name":"SSLCert","fw":4720,"alert":{"decription":99,"level":2},"method":"TLS","prb_id":10008,"dst_port":"443","ttc":31.621485,"src_addr":"134.197.42.163","group_id":3322890,"type":"sslcert","dst_addr":"63.245.213.47","ver":"1.2","msm_id":3322890}') assert(result.alert is not None) assert(result.alert.level == 2) assert(result.alert.description == 99) assert(result.alert.description_string == "Unknown") assert(result.is_error is True) assert(result.error_message == "Unknown") result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIFBTCCAu2gAwIBAgIDDLHHMA0GCSqGSIb3DQEBBQUAMHkxEDAOBgNVBAoTB1Jv\\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\\ndEBjYWNlcnQub3JnMB4XDTEzMDEwNjE0MDA1NVoXDTEzMDcwNTE0MDA1NVowGDEW\\nMBQGA1UEAxQNKi5wcmV0aWNhbC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\\nAQoCggEBAMS+vX7gA8TvzFwxryFFRj1OyQjnW88GvfMuGhKJopalG1EB103oRsxi\\nMcXqwFZUicpqLKHW4lCHcRuhpKoZp8EOILnRAJRKFOjgIrcHQ02Xn4Lf/ewl601h\\n5qxqt1keU1P8j+u9m7zZN+vOoNlEKZ5SnZhysAAYqr/XIt1WY2cji/4GxjF+q1OH\\nIl5zddkIfnE52UbREKKlIakfFdj/c6GXqqsP2QTmm4x2HitCD964tZ06fA9BitQj\\nnnBXNhtm2MCuBIPBSq0/C7LREwmfnqxCFqE7iqEPNIQ2IT2D4Gh4c+nIZHqYKvCV\\nP3zh3aUaBj1o5Lo83IDdXCKAIiQRFMkCAwEAAaOB9jCB8zAMBgNVHRMBAf8EAjAA\\nMA4GA1UdDwEB/wQEAwIDqDA0BgNVHSUELTArBggrBgEFBQcDAgYIKwYBBQUHAwEG\\nCWCGSAGG+EIEAQYKKwYBBAGCNwoDAzAzBggrBgEFBQcBAQQnMCUwIwYIKwYBBQUH\\nMAGGF2h0dHA6Ly9vY3NwLmNhY2VydC5vcmcvMDEGA1UdHwQqMCgwJqAkoCKGIGh0\\ndHA6Ly9jcmwuY2FjZXJ0Lm9yZy9yZXZva2UuY3JsMDUGA1UdEQQuMCyCDSoucHJl\\ndGljYWwuZWWgGwYIKwYBBQUHCAWgDwwNKi5wcmV0aWNhbC5lZTANBgkqhkiG9w0B\\nAQUFAAOCAgEAycddS/c47eo0WVrFxpvCIJdfvn7CYdTPpXNSg0kjapkSjYuAkcmq\\nsrScUUGMBe6tfkmkdPTuNKwRVYNJ1Wi9EYaMvJ3CVw6x9O5mgktmu0ogbIXsivwI\\nTSzGDMWcb9Of85e/ALWpK0cWIugtWO0d6v3qMWfxlYfAaYu49pttOJQOjbXAAhfR\\njE5VOcDaIlWChG48jLAyCLsMwHlyLw8D5Myb9MfTs1XxgLESO9ZTSqGEqJw+BwTJ\\nstHk/oCHo9FL/Xv5MmFcNaTpqbB60duYJ+DLLX1QiRRfLJ18G7wEiEAm6H9egupQ\\nL9MhQQLJ4o60xTrCnpqGTXTSR16jiTm70bDB0+SU3xTpNwCzdigH6ceKbPIr0cO6\\no0ump598e2JNCPsXIc+XcbLDDFgYrlnl3YnK3J+K3LC7SWPMsYdDfe+Im880tNuW\\nOlnOCDpP8408KqCp4xm0DMznmThUM34/Ia+o8Q3NWNBfuaOsJ9aA+FmgobJhih9e\\nUr9x3ByRQXcW5Cs/AMtCikKWVPsx+IA5eeyt+1i+dKBWksO40B3ADsq1O5DRYYRa\\n+dwqdX/jduqZjbyHuFH04q28j4zVDviUBQEa9UQoDM3c82dILDjbYtZ+T28sPMTa\\nbMZdcMur9E+ovrS58lIKGCvDEPSUDXHzr0tpb4A13TTnxW6pclqUyJk=\\n-----END CERTIFICATE-----"],"dst_addr":"80.79.115.54","dst_name":"pretical.ee","dst_port":"https","from":"77.95.64.18","fw":4480,"method":"SSL","msm_id":1006864,"prb_id":517,"src_addr":"77.95.64.18","timestamp":1362454627,"type":"sslcert","ver":"3.0"}') assert(result.alert is None) assert(result.is_error is False) def test_san_extension(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\nMI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5nb29nbGUuY29tL29jc3Aw\nHQYDVR0OBBYEFHRy1woLF5IqQVubJZ5ZvXAjaJ0aMAwGA1UdEwEB/wQCMAAwHwYD\nVR0jBBgwFoAUSt0GFhu89mi1dvWBtrtiGrpagS8wIQYDVR0gBBowGDAMBgorBgEE\nAdZ5AgUBMAgGBmeBDAECAjAwBgNVHR8EKTAnMCWgI6Ahhh9odHRwOi8vcGtpLmdv\nb2dsZS5jb20vR0lBRzIuY3JsMA0GCSqGSIb3DQEBCwUAA4IBAQAsoPR1jJz2adkK\nTVXpGse/M3l+xKgmuZHpXzXkAiqE9wcsxXxCU3dEUmPBYYGRTqODNkOh9AMyGzIL\nfrYh/zY9rhqJ2B26OunmxKFF9BmwRi2rp+Ksvg/+27F57Hyaq2phSaR8E7hRZcYR\nYqCaNA5e1hialuB1g58mAvs38jxxV4bQhKzCKkBOxolhYbUEBEV4mQ14ODdSvAB0\n8L1dMjk3+LEDB/hWdtpOOhtMbSPa1u7xJeM/Ip7+GV47lS3V6rUALDKz4ASNk8ih\nX0ZmxPA1rabqNFutG8L/4HK2/ffO4bKEkHEdOQXC9B17n1x65fbLUbweDPDAzaow\nrum/OChG\n-----END CERTIFICATE-----"],"dst_addr":"193.0.6.158","dst_name":"atlas.ripe.net","dst_port":"443","from":"86.82.178.27","fw":4760,"lts":133,"method":"TLS","msm_id":14002,"msm_name":"SSLCert","prb_id":10951,"rt":51.558465,"src_addr":"192.168.180.22","timestamp":1490659208,"ttc":14.88238,"type":"sslcert","ver":"1.2"}') ext = result.certificates[0].extensions assert(ext and len(ext['subjectAltName'])==54) def test_ssl_error(): result = Result.get('{"dst_name": "example.com","dst_port": "443","error": "address not allowed","from":"10.1.1.1","fw": 4760,"group_id": 1234567,"lts": 10,"msm_id": 1234567,"msm_name": "SSLCert","prb_id": 9999,"timestamp": 1495451999,"type": "sslcert"}') assert(result.is_error is True) assert(result.error_message == "address not allowed") def test_ssl_x509_san(): result = Result.get('{"lts":45,"rt":67.073945,"msm_id":8844155,"from":"185.116.201.100","dst_name":"tinkoff.ru","af":4,"timestamp":1497464532,"fw":4780,"cert":["-----BEGIN CERTIFICATE-----\nMIIEsTCCA5mgAwIBAgIQV1CAInv97wvzUjqHD0BbyzANBgkqhkiG9w0BAQsFADBB\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhhd3RlLCBJbmMuMRswGQYDVQQDExJ0\naGF3dGUgU1NMIENBIC0gRzIwHhcNMTUxMDIwMDAwMDAwWhcNMTcxMjE4MjM1OTU5\nWjBqMQswCQYDVQQGEwJSVTEPMA0GA1UECBMGTW9zY293MQ8wDQYDVQQHFAZNb3Nj\nb3cxFTATBgNVBAoUDFRpbmtvZmYgQmFuazELMAkGA1UECxQCSVQxFTATBgNVBAMU\nDCoudGlua29mZi5ydTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN4W\ncKDTHE470BZWvUBpgce4nMWH9lNa2KWCbrcFMUcqtMaFVh4tp53gKvlvaJyecQ9y\noQBrJycdp7Du8R7HFUwgALBMxjVsrSdai3wS6txCpXJCuT+92spwyuVOT3ZGjXip\n5EwVxXuXNMbi3+alSuX1ocM3m9FWas\/fvhreQZYxpx6CH0+eqpinbTOwYc\/7gvh0\nMJdl+ESN9j9FE87aCTC\/VMakxOIRHsyApG0XNegUj3Fs2HO0XrIxMSqSrCuZqs0q\nUXINGTIoVJVgU4fzuJad2jLrzePDkliKZDZ6JZaeSKQsGgB7mNbCFwCW1oUyepHn\nASHG7BrAiP6tBbiwLHMCAwEAAaOCAXowggF2MCMGA1UdEQQcMBqCDCoudGlua29m\nZi5ydYIKdGlua29mZi5ydTAJBgNVHRMEAjAAMG4GA1UdIARnMGUwYwYGZ4EMAQIC\nMFkwJgYIKwYBBQUHAgEWGmh0dHBzOi8vd3d3LnRoYXd0ZS5jb20vY3BzMC8GCCsG\nAQUFBwICMCMMIWh0dHBzOi8vd3d3LnRoYXd0ZS5jb20vcmVwb3NpdG9yeTAOBgNV\nHQ8BAf8E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PoSgAfGcq\/gcfomk\n6KHYcWUNo1F77rzSImANuVud37r8UVsLr5iy6S7pBOhih94ryNdOwUxkHt3Ph1i6\nSk\/KaAcdHJ1KxtUvkcx8cXIcxcBn6zL9yZJclNqFwJu\/U30rCfSMnZEfl2pSy94J\nNqR32HuHUETVPm4pafs5SSYeCaWAe0At6+gnhcn+Yf1+5nyXHdWdAgMBAAGjQjBA\nMA8GA1UdEwEB\/wQFMAMBAf8wDgYDVR0PAQH\/BAQDAgEGMB0GA1UdDgQWBBR7W0XP\nr87Lev0xkhpqtvNG61dIUDANBgkqhkiG9w0BAQUFAAOCAQEAeRHAS7ORtvzw6WfU\nDW5FvlXok9LOAz\/t2iWwHVfLHjp2oEzsUHboZHIMpKnxuIvW1oeEuzLlQRHAd9mz\nYJ3rG9XRbkREqaYB7FViHXe4XI5ISXycO1cRrK1zN44veFyQaEfZYGDm\/Ac9IiAX\nxPcW6cTYcvnIc3zfFi8VqT79aie2oetaupgf1eNNZAqdE8hhuvU5HIe6uL17In\/2\n\/qxAeeWsEG89jxt5dovEN7MhGITlNgDrYyCZuen+MwS7QcjBAvlEYyCegc5C09Y\/\nLHbTY5xZ3Y+m4Q6gLkH3LpVHz7z9M\/P2C2F+fpErgUfCJzDupxBdN49cOSvkBPB7\njVaMaA==\n-----END CERTIFICATE-----"],"method":"TLS","prb_id":10096,"dst_port":"443","dst_addr":"178.248.236.31","ttc":33.09869,"src_addr":"185.116.201.100","group_id":8844155,"type":"sslcert","msm_name":"SSLCert","ver":"1.2"}') assert(not result.is_error) extensions = [c.extensions for c in result.certificates] should_be = [ {"subjectAltName": [u"*.tinkoff.ru", u"tinkoff.ru"]}, {"subjectAltName": ["/CN=SymantecPKI-1-537"]}, {}, ] assert extensions == should_be def test_invalid_country_code(): result = Result.get('{"af":4,"cert":["-----BEGIN CERTIFICATE-----\\nMIIENTCCAx2gAwIBAgIBADANBgkqhkiG9w0BAQUFADBzMQ8wDQYDVQQGEwZCcmF6\\naWwxCTAHBgN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UFAAOCAQEAVSqrE2xMOqOMT/0r0ijSJVJjMRtdd2WPnpFLZsIt5siHXZHitoF/\\nFLlgaDfWd70uVlL8EjGHxwKPJL2l8WU1foCKCHUA7syarvpQEpm3kaGAoPm8VPm8\\n/ZcjetBxvAF0ZImoAcNE66aanPRSCvcna/5ANgHyZp6a0i7DT/Tqd+/0U3PNZK0Z\\nI7K2HvWx8wgN9WnMwEcNDVw9/pvNpC4Uh4MNDXYJZeC1xMNlB3sfm/ohP15lPsxI\\nN2afNemOosSyqViiPCVl6HaEwrR7YZB2wffnMAC2RAkJYyRkv/V5L4Hf4xz3C+Bl\\n47GfJQP8dNoGhIt1iCtMQp1iRNUfYCuqhQ==\\n-----END CERTIFICATE-----"],"dst_addr":"199.7.83.80","dst_name":"199.7.83.80","dst_port":"443","from":"123.203.145.125","fw":4790,"group_id":1965073,"lts":54,"method":"TLS","msm_id":1965073,"msm_name":"SSLCert","prb_id":1004,"rt":701.811596,"src_addr":"192.168.1.100","timestamp":1502117346,"ttc":346.966342,"type":"sslcert","ver":"1.2"}') assert(result.is_error) print(type(result.error_message), result.error_message) assert(result.error_message == "Country name must be a 2 character country code") ripe-atlas-sagan-1.3.1/tests/traceroute.py000066400000000000000000002245331405365472700205630ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from ripe.atlas.sagan import Result from ripe.atlas.sagan.traceroute import TracerouteResult, Hop, Packet def test_traceroute_4460(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1340329208,"from":"107.3.81.49","fw":4460,"msm_id":1000157,"paris_id":2,"prb_id":190,"proto":"UDP","result":[{"hop":1,"result":[{"from":"192.168.1.1","rtt":2.7829999999999999,"size":96,"ttl":64},{"from":"192.168.1.1","rtt":2.4500000000000002,"size":96,"ttl":64},{"from":"192.168.1.1","rtt":2.3210000000000002,"size":96,"ttl":64}]},{"hop":2,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":3,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":4,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":5,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":6,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"192.168.1.107","timestamp":1340329190,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2012-06-22T01:40:08+00:00") assert(result.origin == "107.3.81.49") assert(result.firmware == 4460) assert(result.measurement_id == 1000157) assert(result.probe_id == 190) assert(result.paris_id == 2) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 7) assert(result.last_median_rtt == 2.45) assert(result.ip_path[3][1] is None) assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin is None) assert(result.hops[3].packets[1].rtt is None) assert(result.hops[3].packets[1].size is None) assert(result.hops[3].packets[2].ttl is None) assert(result.hops[-1].index == 255) def test_traceroute_4470(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1344429608,"from":"216.66.30.82","fw":4470,"msm_id":1000157,"paris_id":1,"prb_id":426,"proto":"UDP","result":[{"hop":1,"result":[{"from":"216.66.30.81","rtt":1.9650000000000001,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":2.004,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":1.855,"size":56,"ttl":255}]},{"hop":2,"result":[{"from":"64.71.128.50","rtt":1.843,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":2.004,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":1.8580000000000001,"size":56,"ttl":63}]},{"hop":3,"result":[{"from":"213.248.79.129","rtt":2.4220000000000002,"size":56,"ttl":253},{"from":"213.248.79.129","rtt":1.8700000000000001,"size":56,"ttl":253},{"from":"213.248.79.129","rtt":1.8740000000000001,"size":56,"ttl":253}]},{"hop":4,"result":[{"from":"80.91.250.102","rtt":2.327,"size":56,"ttl":251},{"from":"80.91.250.102","rtt":2.0760000000000001,"size":56,"ttl":251},{"from":"80.91.250.102","rtt":2.3210000000000002,"size":56,"ttl":251}]},{"hop":5,"result":[{"from":"213.155.135.79","rtt":2.7010000000000001,"size":56,"ttl":251},{"from":"213.155.135.79","rtt":2.5030000000000001,"size":56,"ttl":251},{"from":"213.155.135.79","rtt":9.9969999999999999,"size":56,"ttl":251}]},{"hop":6,"result":[{"from":"209.58.26.89","rtt":2.5760000000000001,"size":56,"ttl":250},{"from":"209.58.26.89","rtt":2.6640000000000001,"size":56,"ttl":250},{"from":"209.58.26.89","rtt":14.355,"size":56,"ttl":250}]},{"hop":7,"result":[{"from":"195.219.243.21","rtt":71.448999999999998,"size":56,"ttl":249},{"from":"195.219.243.21","rtt":71.435000000000002,"size":56,"ttl":249},{"from":"195.219.243.21","rtt":71.311000000000007,"size":56,"ttl":249}]},{"hop":8,"result":[{"from":"80.231.131.10","rtt":71.504000000000005,"size":56,"ttl":249},{"from":"80.231.131.10","rtt":71.540000000000006,"size":56,"ttl":249},{"from":"80.231.131.10","rtt":71.484999999999999,"size":56,"ttl":249}]},{"hop":9,"result":[{"from":"195.219.144.118","rtt":197.21299999999999,"size":56,"ttl":246},{"from":"195.219.144.118","rtt":222.99100000000001,"size":56,"ttl":246},{"from":"195.219.144.118","rtt":196.874,"size":56,"ttl":246}]},{"hop":10,"result":[{"from":"59.163.16.13","ittl":0,"rtt":197.03399999999999,"size":56,"ttl":245},{"from":"59.163.16.13","ittl":0,"rtt":200.82900000000001,"size":56,"ttl":245},{"from":"59.163.16.13","ittl":0,"rtt":196.88900000000001,"size":56,"ttl":245}]},{"hop":11,"result":[{"from":"59.163.16.13","rtt":197.04599999999999,"size":56,"ttl":245},{"from":"59.163.16.13","rtt":196.92699999999999,"size":56,"ttl":245},{"from":"59.163.16.13","rtt":196.96199999999999,"size":56,"ttl":245}]},{"hop":12,"result":[{"from":"203.197.33.148","rtt":197.33099999999999,"size":56,"ttl":245},{"from":"203.197.33.148","rtt":197.398,"size":56,"ttl":245},{"from":"203.197.33.148","rtt":197.34800000000001,"size":56,"ttl":245}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":17,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"216.66.30.82","timestamp":1344429586,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2012-08-08T12:40:08+00:00") assert(result.origin == "216.66.30.82") assert(result.firmware == 4470) assert(result.measurement_id == 1000157) assert(result.probe_id == 426) assert(result.paris_id == 1) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 18) assert(result.last_median_rtt == 197.348) assert(result.last_rtt == 197.348) # Deprecation test assert(result.ip_path[3][1] == "80.91.250.102") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "80.91.250.102") assert(result.hops[3].packets[1].rtt == 2.076) assert(result.hops[3].packets[1].size == 56) assert(result.hops[3].packets[2].ttl == 251) assert(result.hops[-1].index == 255) def test_traceroute_4480(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1349840414,"from":"216.66.30.82","fw":4480,"msm_id":1000157,"paris_id":1,"prb_id":426,"proto":"UDP","result":[{"hop":1,"result":[{"from":"216.66.30.81","rtt":2.133,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":1.8360000000000001,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":1.8400000000000001,"size":56,"ttl":255}]},{"hop":2,"result":[{"from":"64.71.128.50","rtt":3.5990000000000002,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":8.4779999999999998,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":3.6499999999999999,"size":56,"ttl":63}]},{"hop":3,"result":[{"from":"72.52.92.102","rtt":7.5289999999999999,"size":56,"ttl":62},{"from":"72.52.92.102","rtt":1.847,"size":56,"ttl":62},{"from":"72.52.92.102","rtt":1.8380000000000001,"size":56,"ttl":62}]},{"hop":4,"result":[{"from":"213.248.101.145","rtt":1.8340000000000001,"size":56,"ttl":252},{"from":"213.248.101.145","rtt":1.9830000000000001,"size":56,"ttl":252},{"from":"213.248.101.145","rtt":1.9279999999999999,"size":56,"ttl":252}]},{"hop":5,"result":[{"from":"80.91.248.177","rtt":2.3290000000000002,"size":56,"ttl":250},{"from":"80.91.248.177","rtt":2.2400000000000002,"size":56,"ttl":250},{"from":"80.91.248.177","rtt":2.2370000000000001,"size":56,"ttl":250}]},{"hop":6,"result":[{"from":"213.155.135.79","rtt":22.812999999999999,"size":56,"ttl":251},{"from":"213.155.135.79","rtt":22.091000000000001,"size":56,"ttl":251},{"from":"213.155.135.79","rtt":2.3100000000000001,"size":56,"ttl":251}]},{"hop":7,"result":[{"from":"213.248.100.178","rtt":2.5710000000000002,"size":56,"ttl":250},{"from":"213.248.100.178","rtt":2.5049999999999999,"size":56,"ttl":250},{"x":"*"}]},{"hop":8,"result":[{"from":"195.219.243.21","rtt":71.701999999999998,"size":56,"ttl":249},{"from":"195.219.243.21","rtt":71.295000000000002,"size":56,"ttl":249},{"from":"195.219.243.21","rtt":71.734999999999999,"size":56,"ttl":249}]},{"hop":9,"result":[{"from":"80.231.131.10","rtt":71.626000000000005,"size":56,"ttl":249},{"from":"80.231.131.10","rtt":71.313000000000002,"size":56,"ttl":249},{"from":"80.231.131.10","rtt":71.253,"size":56,"ttl":249}]},{"hop":10,"result":[{"from":"195.219.144.62","rtt":205.416,"size":56,"ttl":245},{"from":"195.219.144.62","rtt":200.53,"size":56,"ttl":245},{"from":"195.219.144.62","rtt":200.39500000000001,"size":56,"ttl":245}]},{"hop":11,"result":[{"from":"59.163.55.149","ittl":0,"rtt":200.755,"size":56,"ttl":244},{"from":"59.163.55.149","ittl":0,"rtt":200.41,"size":56,"ttl":244},{"from":"59.163.55.149","ittl":0,"rtt":200.40799999999999,"size":56,"ttl":244}]},{"hop":12,"result":[{"from":"59.163.55.149","rtt":200.572,"size":56,"ttl":244},{"from":"59.163.55.149","rtt":200.584,"size":56,"ttl":244},{"from":"59.163.55.149","rtt":200.673,"size":56,"ttl":244}]},{"hop":13,"result":[{"from":"203.197.33.148","rtt":198.666,"size":56,"ttl":244},{"from":"203.197.33.148","rtt":198.83699999999999,"size":56,"ttl":244},{"from":"203.197.33.148","rtt":198.55099999999999,"size":56,"ttl":244}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":17,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":18,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"216.66.30.82","timestamp":1349840391,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2012-10-10T03:40:14+00:00") assert(result.origin == "216.66.30.82") assert(result.firmware == 4480) assert(result.measurement_id == 1000157) assert(result.probe_id == 426) assert(result.paris_id == 1) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 19) assert(result.last_median_rtt == 198.666) assert(result.ip_path[3][1] == "213.248.101.145") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "213.248.101.145") assert(result.hops[3].packets[1].rtt == 1.983) assert(result.hops[3].packets[1].size == 56) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_4500(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1361436009,"from":"192.172.226.243","fw":4500,"msm_id":1000157,"paris_id":1,"prb_id":319,"proto":"UDP","result":[{"hop":1,"result":[{"from":"192.172.226.252","rtt":2.0209999999999999,"size":56,"ttl":254},{"from":"192.172.226.252","rtt":1.7589999999999999,"size":56,"ttl":254},{"from":"192.172.226.252","rtt":1.7589999999999999,"size":56,"ttl":254}]},{"hop":2,"result":[{"from":"192.12.207.61","rtt":1.8999999999999999,"size":56,"ttl":253},{"from":"192.12.207.61","rtt":1.7549999999999999,"size":56,"ttl":253},{"from":"192.12.207.61","rtt":1.9079999999999999,"size":56,"ttl":253}]},{"hop":3,"result":[{"from":"137.164.23.129","rtt":1.859,"size":56,"ttl":253},{"from":"137.164.23.129","rtt":1.7669999999999999,"size":56,"ttl":253},{"from":"137.164.23.129","rtt":1.9099999999999999,"size":56,"ttl":253}]},{"hop":4,"result":[{"from":"137.164.47.110","rtt":10.246,"size":56,"ttl":252},{"from":"137.164.47.110","rtt":9.8439999999999994,"size":56,"ttl":252},{"from":"137.164.47.110","rtt":10.106999999999999,"size":56,"ttl":252}]},{"hop":5,"result":[{"from":"137.164.46.57","rtt":11.597,"size":56,"ttl":251},{"from":"137.164.46.57","rtt":11.255000000000001,"size":56,"ttl":251},{"from":"137.164.46.57","rtt":11.279999999999999,"size":56,"ttl":251}]},{"hop":6,"result":[{"from":"137.164.47.136","rtt":11.24,"size":56,"ttl":250},{"from":"137.164.47.136","rtt":11.099,"size":56,"ttl":250},{"from":"137.164.47.136","rtt":11.096,"size":56,"ttl":250}]},{"hop":7,"result":[{"from":"4.59.48.177","rtt":11.287000000000001,"size":56,"ttl":248},{"from":"4.59.48.177","rtt":11.201000000000001,"size":56,"ttl":248},{"from":"4.59.48.177","rtt":11.204000000000001,"size":56,"ttl":248}]},{"hop":8,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":9,"result":[{"from":"4.68.62.118","rtt":11.532999999999999,"size":56,"ttl":247},{"from":"4.68.62.118","rtt":11.298999999999999,"size":56,"ttl":247},{"from":"4.68.62.118","rtt":11.474,"size":56,"ttl":247}]},{"hop":10,"result":[{"from":"66.110.59.1","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":407904,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":23.974,"size":168,"ttl":241},{"from":"66.110.59.1","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":407904,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":27.079000000000001,"size":168,"ttl":241},{"from":"66.110.59.1","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":407904,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":23.843,"size":168,"ttl":241}]},{"hop":11,"result":[{"from":"66.198.127.9","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":371728,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":23.997,"size":168,"ttl":242},{"from":"66.198.127.9","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":371728,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":46.223999999999997,"size":168,"ttl":242},{"from":"66.198.127.9","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":371728,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":24.052,"size":168,"ttl":242}]},{"hop":12,"result":[{"from":"66.198.127.2","rtt":23.966999999999999,"size":56,"ttl":244},{"from":"66.198.127.2","rtt":24.617000000000001,"size":56,"ttl":244},{"from":"66.198.127.2","rtt":24.991,"size":56,"ttl":244}]},{"hop":13,"result":[{"from":"66.198.144.2","rtt":268.68200000000002,"size":56,"ttl":233},{"from":"66.198.144.2","rtt":268.93299999999999,"size":56,"ttl":233},{"from":"66.198.144.2","rtt":268.45999999999998,"size":56,"ttl":233}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":17,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":18,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"192.172.226.243","timestamp":1361435986,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2013-02-21T08:40:09+00:00") assert(result.origin == "192.172.226.243") assert(result.firmware == 4500) assert(result.measurement_id == 1000157) assert(result.probe_id == 319) assert(result.paris_id == 1) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 19) assert(result.last_median_rtt == 268.682) assert(result.ip_path[3][1] == "137.164.47.110") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "137.164.47.110") assert(result.hops[3].packets[1].rtt == 9.844) assert(result.hops[3].packets[1].size == 56) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_4520(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1365381605,"from":"216.66.30.82","fw":4520,"msm_id":1000157,"paris_id":12,"prb_id":426,"proto":"UDP","result":[{"hop":1,"result":[{"from":"216.66.30.81","rtt":2.0720000000000001,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":1.7829999999999999,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":1.9399999999999999,"size":56,"ttl":255}]},{"hop":2,"result":[{"from":"64.71.128.50","rtt":8.0690000000000008,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":3.3690000000000002,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":7.891,"size":56,"ttl":63}]},{"hop":3,"result":[{"from":"72.52.92.49","rtt":27.738,"size":56,"ttl":62},{"from":"72.52.92.49","rtt":58.445,"size":56,"ttl":62},{"from":"72.52.92.49","rtt":79.837000000000003,"size":56,"ttl":62}]},{"hop":4,"result":[{"from":"213.248.67.125","rtt":101.46899999999999,"size":56,"ttl":252},{"from":"213.248.67.125","rtt":83.983999999999995,"size":56,"ttl":252},{"from":"213.248.67.125","rtt":1.869,"size":56,"ttl":252}]},{"hop":5,"result":[{"from":"213.155.131.254","rtt":1.8879999999999999,"size":56,"ttl":251},{"from":"213.155.131.254","rtt":1.7869999999999999,"size":56,"ttl":251},{"from":"213.155.131.254","rtt":1.9339999999999999,"size":56,"ttl":251}]},{"hop":6,"result":[{"from":"213.248.100.178","rtt":3.8559999999999999,"size":56,"ttl":249},{"from":"213.248.100.178","rtt":1.7989999999999999,"size":56,"ttl":249},{"from":"213.248.100.178","rtt":1.897,"size":56,"ttl":249}]},{"hop":7,"result":[{"from":"63.243.128.38","rtt":71.748000000000005,"size":56,"ttl":249},{"from":"63.243.128.38","rtt":80.543999999999997,"size":56,"ttl":249},{"from":"63.243.128.38","rtt":71.480000000000004,"size":56,"ttl":249}]},{"hop":8,"result":[{"from":"80.231.131.114","rtt":203.08600000000001,"size":56,"ttl":249},{"from":"80.231.131.114","rtt":202.63,"size":56,"ttl":249},{"from":"80.231.131.114","rtt":202.63999999999999,"size":56,"ttl":249}]},{"hop":9,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":10,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":11,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":12,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"216.66.30.82","timestamp":1365381585,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2013-04-08T00:40:05+00:00") assert(result.origin == "216.66.30.82") assert(result.firmware == 4520) assert(result.measurement_id == 1000157) assert(result.probe_id == 426) assert(result.paris_id == 12) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 14) assert(result.last_median_rtt == 202.64) assert(result.ip_path[3][1] == "213.248.67.125") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "213.248.67.125") assert(result.hops[3].packets[1].rtt == 83.984) assert(result.hops[3].packets[1].size == 56) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_4550(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1378186817,"from":"24.61.47.146","fw":4550,"msm_id":1000157,"msm_name":"Traceroute","paris_id":1,"prb_id":190,"proto":"UDP","result":[{"hop":1,"result":[{"from":"192.168.11.1","rtt":1.8919999999999999,"size":96,"ttl":64},{"from":"192.168.11.1","rtt":1.75,"size":96,"ttl":64},{"from":"192.168.11.1","rtt":1.744,"size":96,"ttl":64}]},{"hop":2,"result":[{"from":"96.120.64.225","rtt":12.012,"size":56,"ttl":254},{"from":"96.120.64.225","rtt":25.962,"size":56,"ttl":254},{"from":"96.120.64.225","rtt":11.657999999999999,"size":56,"ttl":254}]},{"hop":3,"result":[{"from":"68.85.140.197","rtt":10.077999999999999,"size":56,"ttl":253},{"from":"68.85.140.197","rtt":12.561999999999999,"size":56,"ttl":253},{"from":"68.85.140.197","rtt":14.548999999999999,"size":56,"ttl":253}]},{"hop":4,"result":[{"from":"68.87.144.69","rtt":10.404,"size":56,"ttl":253},{"from":"68.87.144.69","rtt":10.539999999999999,"size":56,"ttl":253},{"from":"68.87.144.69","rtt":10.07,"size":56,"ttl":253}]},{"hop":5,"result":[{"from":"68.85.162.157","rtt":28.190999999999999,"size":96,"ttl":252},{"from":"68.85.162.157","rtt":15.026,"size":96,"ttl":252},{"from":"68.85.162.157","rtt":13.1,"size":96,"ttl":252}]},{"hop":6,"result":[{"from":"68.86.93.185","rtt":40.353000000000002,"size":96,"ttl":250},{"from":"68.86.93.185","rtt":44.490000000000002,"size":96,"ttl":250},{"from":"68.86.93.185","rtt":40.649000000000001,"size":96,"ttl":250}]},{"hop":7,"result":[{"from":"68.86.86.74","rtt":42.399000000000001,"size":96,"ttl":249},{"from":"68.86.86.74","rtt":42.179000000000002,"size":96,"ttl":249},{"from":"68.86.86.74","rtt":46.326000000000001,"size":96,"ttl":249}]},{"hop":8,"result":[{"from":"209.58.26.81","rtt":40.264000000000003,"size":56,"ttl":248},{"from":"209.58.26.81","rtt":37.850999999999999,"size":56,"ttl":248},{"from":"209.58.26.81","rtt":44.194000000000003,"size":56,"ttl":248}]},{"hop":9,"result":[{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":674080,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":273.74099999999999,"size":168,"ttl":239},{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":674080,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":272.11099999999999,"size":168,"ttl":239},{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":674080,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":271.76499999999999,"size":168,"ttl":239}]},{"hop":10,"result":[{"from":"80.231.200.13","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":371312,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":271.88,"size":168,"ttl":240},{"from":"80.231.200.13","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":371312,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":278.21100000000001,"size":168,"ttl":240},{"from":"80.231.200.13","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":371312,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":274.62799999999999,"size":168,"ttl":240}]},{"hop":11,"result":[{"from":"80.231.217.1","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":545488,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":275.60899999999998,"size":168,"ttl":241},{"from":"80.231.217.1","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":545488,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":278.06900000000002,"size":168,"ttl":241},{"from":"80.231.217.1","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":545488,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":276.13799999999998,"size":168,"ttl":241}]},{"hop":12,"result":[{"from":"80.231.217.18","rtt":295.97000000000003,"size":56,"ttl":243},{"from":"80.231.217.18","rtt":284.20299999999997,"size":56,"ttl":243},{"from":"80.231.217.18","rtt":283.91300000000001,"size":56,"ttl":243}]},{"hop":13,"result":[{"from":"180.87.38.6","rtt":268.40899999999999,"size":56,"ttl":237},{"from":"180.87.38.6","rtt":277.73099999999999,"size":56,"ttl":237},{"from":"180.87.38.6","rtt":268.12,"size":56,"ttl":237}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":17,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":18,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"192.168.11.151","timestamp":1378186793,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2013-09-03T05:40:17+00:00") assert(result.origin == "24.61.47.146") assert(result.firmware == 4550) assert(result.measurement_id == 1000157) assert(result.probe_id == 190) assert(result.paris_id == 1) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 19) assert(result.last_median_rtt == 268.409) assert(result.ip_path[3][1] == "68.87.144.69") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "68.87.144.69") assert(result.hops[3].packets[1].rtt == 10.54) assert(result.hops[3].packets[1].size == 56) assert(result.hops[3].packets[2].ttl == 253) assert(result.hops[-1].index == 255) def test_traceroute_4560(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1380595207,"from":"216.66.30.82","fw":4560,"msm_id":1000157,"msm_name":"Traceroute","paris_id":1,"prb_id":426,"proto":"UDP","result":[{"hop":1,"result":[{"from":"216.66.30.81","rtt":137.40299999999999,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":103.331,"size":56,"ttl":255},{"from":"216.66.30.81","rtt":7.6379999999999999,"size":56,"ttl":255}]},{"hop":2,"result":[{"from":"64.71.128.50","rtt":1.756,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":3.1059999999999999,"size":56,"ttl":63},{"from":"64.71.128.50","rtt":1.905,"size":56,"ttl":63}]},{"hop":3,"result":[{"from":"184.105.222.81","rtt":2.0470000000000002,"size":56,"ttl":62},{"from":"184.105.222.81","rtt":2.0569999999999999,"size":56,"ttl":62},{"from":"184.105.222.81","rtt":1.768,"size":56,"ttl":62}]},{"hop":4,"result":[{"from":"213.248.67.125","rtt":1.762,"size":56,"ttl":252},{"from":"213.248.67.125","rtt":1.764,"size":56,"ttl":252},{"from":"213.248.67.125","rtt":62.124000000000002,"size":56,"ttl":252}]},{"hop":5,"result":[{"from":"213.155.130.34","rtt":1.8620000000000001,"size":56,"ttl":251},{"from":"213.155.130.34","rtt":3.028,"size":56,"ttl":251},{"from":"213.155.130.34","rtt":2.9990000000000001,"size":56,"ttl":251}]},{"hop":6,"result":[{"from":"213.248.100.178","rtt":4.25,"size":56,"ttl":250},{"from":"213.248.100.178","rtt":2.512,"size":56,"ttl":250},{"from":"213.248.100.178","rtt":1.869,"size":56,"ttl":250}]},{"hop":7,"result":[{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":310273,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":97.242999999999995,"size":168,"ttl":240},{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":310273,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":111.867,"size":168,"ttl":240},{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":310273,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":96.531999999999996,"size":168,"ttl":240}]},{"hop":8,"result":[{"from":"80.231.130.121","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":798112,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":102.61,"size":168,"ttl":241},{"from":"80.231.130.121","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":798112,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":132.82499999999999,"size":168,"ttl":241},{"from":"80.231.130.121","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":798112,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":103.658,"size":168,"ttl":241}]},{"hop":9,"result":[{"from":"80.231.130.2","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":301041,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":102.482,"size":168,"ttl":242},{"from":"80.231.130.2","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":301041,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":102.691,"size":168,"ttl":242},{"from":"80.231.130.2","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":301041,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":102.435,"size":168,"ttl":242}]},{"hop":10,"result":[{"from":"80.231.217.5","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":302880,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":97.114999999999995,"size":168,"ttl":243},{"from":"80.231.217.5","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":302880,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":96.379000000000005,"size":168,"ttl":243},{"from":"80.231.217.5","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":302880,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":96.712999999999994,"size":168,"ttl":243}]},{"hop":11,"result":[{"from":"80.231.217.2","rtt":168.09700000000001,"size":56,"ttl":245},{"from":"80.231.217.2","rtt":96.829999999999998,"size":56,"ttl":245},{"from":"80.231.217.2","rtt":103.726,"size":56,"ttl":245}]},{"hop":12,"result":[{"from":"80.231.200.26","rtt":198.64599999999999,"size":56,"ttl":244},{"from":"80.231.200.26","rtt":198.21000000000001,"size":56,"ttl":244},{"from":"80.231.200.26","rtt":206.268,"size":56,"ttl":244}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":17,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"216.66.30.82","timestamp":1380595186,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2013-10-01T02:40:07+00:00") assert(result.origin == "216.66.30.82") assert(result.firmware == 4560) assert(result.measurement_id == 1000157) assert(result.probe_id == 426) assert(result.paris_id == 1) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 18) assert(result.last_median_rtt == 198.646) assert(result.ip_path[3][1] == "213.248.67.125") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "213.248.67.125") assert(result.hops[3].packets[1].rtt == 1.764) assert(result.hops[3].packets[1].size == 56) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_4570(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1392240133,"from":"216.66.30.82","fw":4570,"msm_id":1000157,"msm_name":"Traceroute","paris_id":2,"prb_id":426,"proto":"UDP","result":[{"hop":1,"result":[{"from":"216.66.30.81","rtt":62.367,"size":28,"ttl":255},{"from":"216.66.30.81","rtt":3.038,"size":28,"ttl":255},{"from":"216.66.30.81","rtt":2.895,"size":28,"ttl":255}]},{"hop":2,"result":[{"from":"64.71.128.50","rtt":12.539,"size":28,"ttl":63},{"from":"64.71.128.50","rtt":7.634,"size":28,"ttl":63},{"from":"64.71.128.50","rtt":12.681,"size":28,"ttl":63}]},{"hop":3,"result":[{"from":"184.105.222.81","rtt":12.469,"size":28,"ttl":62},{"from":"184.105.222.81","rtt":6.039,"size":28,"ttl":62},{"from":"184.105.222.81","rtt":13.747,"size":28,"ttl":62}]},{"hop":4,"result":[{"from":"213.248.67.125","rtt":3.466,"size":28,"ttl":252},{"from":"213.248.67.125","rtt":6.483,"size":28,"ttl":252},{"from":"213.248.67.125","rtt":2.901,"size":28,"ttl":252}]},{"hop":5,"result":[{"from":"213.155.130.32","rtt":2.9,"size":28,"ttl":251},{"from":"213.155.130.32","rtt":2.911,"size":28,"ttl":251},{"from":"213.155.130.32","rtt":2.906,"size":28,"ttl":251}]},{"hop":6,"result":[{"from":"213.248.100.178","rtt":2.888,"size":28,"ttl":250},{"from":"213.248.100.178","rtt":2.905,"size":28,"ttl":250},{"from":"213.248.100.178","rtt":2.907,"size":28,"ttl":250}]},{"hop":7,"result":[{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":539153,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":102.323,"size":140,"ttl":243},{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":539153,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":101.937,"size":140,"ttl":243},{"from":"63.243.128.38","icmpext":{"obj":[{"class":1,"mpls":[{"exp":1,"label":539153,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":101.985,"size":140,"ttl":243}]},{"hop":8,"result":[{"from":"80.231.200.13","rtt":118.695,"size":28,"ttl":245},{"from":"80.231.200.13","rtt":167.614,"size":28,"ttl":245},{"from":"80.231.200.13","rtt":104.848,"size":28,"ttl":245}]},{"hop":9,"result":[{"from":"80.231.200.26","rtt":198.423,"size":28,"ttl":242},{"from":"80.231.200.26","rtt":198.483,"size":28,"ttl":242},{"from":"80.231.200.26","rtt":275.198,"size":28,"ttl":242}]},{"hop":10,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":11,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":12,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"216.66.30.82","timestamp":1392240112,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2014-02-12T21:22:13+00:00") assert(result.origin == "216.66.30.82") assert(result.firmware == 4570) assert(result.measurement_id == 1000157) assert(result.probe_id == 426) assert(result.paris_id == 2) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 15) assert(result.last_median_rtt == 198.483) assert(result.ip_path[3][1] == "213.248.67.125") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "213.248.67.125") assert(result.hops[3].packets[1].rtt == 6.483) assert(result.hops[3].packets[1].size == 28) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_4600(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1392240144,"from":"192.172.226.243","fw":4600,"msm_id":1000157,"msm_name":"Traceroute","paris_id":1,"prb_id":319,"proto":"UDP","result":[{"hop":1,"result":[{"from":"192.172.226.252","rtt":1.905,"size":28,"ttl":254},{"from":"192.172.226.252","rtt":1.753,"size":28,"ttl":254},{"from":"192.172.226.252","rtt":1.9,"size":28,"ttl":254}]},{"hop":2,"result":[{"from":"192.12.207.61","rtt":1.895,"size":28,"ttl":253},{"from":"192.12.207.61","rtt":1.894,"size":28,"ttl":253},{"from":"192.12.207.61","rtt":1.91,"size":28,"ttl":253}]},{"hop":3,"result":[{"from":"137.164.23.129","rtt":1.902,"size":28,"ttl":253},{"from":"137.164.23.129","rtt":1.903,"size":28,"ttl":253},{"from":"137.164.23.129","rtt":1.892,"size":28,"ttl":253}]},{"hop":4,"result":[{"from":"137.164.47.14","rtt":13.516,"size":68,"ttl":252},{"from":"137.164.47.14","rtt":11.383,"size":68,"ttl":252},{"from":"137.164.47.14","rtt":13.716,"size":68,"ttl":252}]},{"hop":5,"result":[{"from":"137.164.46.57","rtt":14.907,"size":68,"ttl":251},{"from":"137.164.46.57","rtt":12.637,"size":68,"ttl":251},{"from":"137.164.46.57","rtt":14.947,"size":68,"ttl":251}]},{"hop":6,"result":[{"from":"137.164.47.136","rtt":11.321,"size":28,"ttl":250},{"from":"137.164.47.136","rtt":11.148,"size":28,"ttl":250},{"from":"137.164.47.136","rtt":11.209,"size":28,"ttl":250}]},{"hop":7,"result":[{"from":"4.59.48.177","rtt":11.24,"size":28,"ttl":248},{"from":"4.59.48.177","rtt":11.284,"size":28,"ttl":248},{"from":"4.59.48.177","rtt":11.364,"size":28,"ttl":248}]},{"hop":8,"result":[{"from":"4.69.144.208","rtt":48.435,"size":28,"ttl":248},{"from":"4.69.144.208","rtt":11.359,"size":28,"ttl":248},{"from":"4.69.144.208","rtt":11.29,"size":28,"ttl":248}]},{"hop":9,"result":[{"from":"4.68.62.118","rtt":11.387,"size":28,"ttl":247},{"from":"4.68.62.118","rtt":11.322,"size":28,"ttl":247},{"from":"4.68.62.118","rtt":11.568,"size":28,"ttl":247}]},{"hop":10,"result":[{"from":"66.198.144.73","rtt":23.979,"size":28,"ttl":245},{"from":"66.198.144.73","rtt":23.784,"size":28,"ttl":245},{"from":"66.198.144.73","rtt":23.924,"size":28,"ttl":245}]},{"hop":11,"result":[{"from":"66.198.144.2","rtt":278.829,"size":28,"ttl":229},{"from":"66.198.144.2","rtt":272.012,"size":28,"ttl":229},{"from":"66.198.144.2","rtt":271.775,"size":28,"ttl":229}]},{"hop":12,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"192.172.226.243","timestamp":1392240124,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2014-02-12T21:22:24+00:00") assert(result.origin == "192.172.226.243") assert(result.firmware == 4600) assert(result.measurement_id == 1000157) assert(result.probe_id == 319) assert(result.paris_id == 1) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 17) assert(result.last_median_rtt == 272.012) assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.ip_path[3][1] == "137.164.47.14") assert(result.hops[3].packets[0].origin == "137.164.47.14") assert(result.hops[3].packets[1].rtt == 11.383) assert(result.hops[3].packets[1].size == 68) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_4610(): result = Result.get('{"af":4,"dst_addr":"121.244.76.25","dst_name":"121.244.76.25","endtime":1395833056,"from":"192.172.226.243","fw":4610,"group_id":1000157,"msm_id":1000157,"msm_name":"Traceroute","paris_id":13,"prb_id":319,"proto":"UDP","result":[{"hop":1,"result":[{"from":"192.172.226.252","rtt":5.6970000000000001,"size":28,"ttl":254},{"from":"192.172.226.252","rtt":2.931,"size":28,"ttl":254},{"from":"192.172.226.252","rtt":2.919,"size":28,"ttl":254}]},{"hop":2,"result":[{"from":"192.12.207.61","rtt":3.052,"size":28,"ttl":253},{"from":"192.12.207.61","rtt":2.923,"size":28,"ttl":253},{"from":"192.12.207.61","rtt":2.919,"size":28,"ttl":253}]},{"hop":3,"result":[{"from":"137.164.23.129","rtt":2.9140000000000001,"size":28,"ttl":253},{"from":"137.164.23.129","rtt":3.0579999999999998,"size":28,"ttl":253},{"from":"137.164.23.129","rtt":3.0630000000000002,"size":28,"ttl":253}]},{"hop":4,"result":[{"from":"137.164.47.14","rtt":14.433999999999999,"size":68,"ttl":252},{"from":"137.164.47.14","rtt":17.170999999999999,"size":68,"ttl":252},{"from":"137.164.47.14","rtt":14.332000000000001,"size":68,"ttl":252}]},{"hop":5,"result":[{"from":"137.164.46.57","rtt":14.737,"size":68,"ttl":251},{"from":"137.164.46.57","rtt":16.905000000000001,"size":68,"ttl":251},{"from":"137.164.46.57","rtt":14.532,"size":68,"ttl":251}]},{"hop":6,"result":[{"from":"137.164.47.136","rtt":12.420999999999999,"size":28,"ttl":250},{"from":"137.164.47.136","rtt":12.192,"size":28,"ttl":250},{"from":"137.164.47.136","rtt":12.204000000000001,"size":28,"ttl":250}]},{"hop":7,"result":[{"from":"4.59.48.177","rtt":12.343999999999999,"size":28,"ttl":248},{"from":"4.59.48.177","rtt":12.404,"size":28,"ttl":248},{"from":"4.59.48.177","rtt":12.257999999999999,"size":28,"ttl":248}]},{"hop":8,"result":[{"from":"4.69.144.80","rtt":12.476000000000001,"size":28,"ttl":248},{"from":"4.69.144.80","rtt":12.329000000000001,"size":28,"ttl":248},{"from":"4.69.144.80","rtt":12.473000000000001,"size":28,"ttl":248}]},{"hop":9,"result":[{"from":"4.68.62.118","rtt":12.506,"size":28,"ttl":247},{"from":"4.68.62.118","rtt":12.324,"size":28,"ttl":247},{"from":"4.68.62.118","rtt":12.56,"size":28,"ttl":247}]},{"hop":10,"result":[{"from":"64.86.252.38","rtt":24.934000000000001,"size":28,"ttl":245},{"from":"64.86.252.38","rtt":24.690000000000001,"size":28,"ttl":245},{"from":"64.86.252.38","rtt":24.913,"size":28,"ttl":245}]},{"hop":11,"result":[{"from":"66.198.144.2","rtt":297.88499999999999,"size":28,"ttl":232},{"from":"66.198.144.2","rtt":273.28500000000003,"size":28,"ttl":232},{"from":"66.198.144.2","rtt":273.49400000000003,"size":28,"ttl":232}]},{"hop":12,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":14,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":15,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":16,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"192.172.226.243","timestamp":1395833036,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(isinstance(result.hops[0], Hop)) assert(isinstance(result.hops[0].packets[0], Packet)) assert(result.af == 4) assert(result.destination_address == "121.244.76.25") assert(result.destination_name == "121.244.76.25") assert(result.end_time.isoformat() == "2014-03-26T11:24:16+00:00") assert(result.origin == "192.172.226.243") assert(result.firmware == 4610) assert(result.measurement_id == 1000157) assert(result.probe_id == 319) assert(result.paris_id == 13) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 17) assert(result.last_median_rtt == 273.494) assert(result.destination_ip_responded is False) assert(result.last_hop_responded is False) assert(result.is_success is False) assert(result.ip_path[3][1] == "137.164.47.14") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[3].index == 4) assert(result.hops[3].packets[0].origin == "137.164.47.14") assert(result.hops[3].packets[1].rtt == 17.171) assert(result.hops[3].packets[1].size == 68) assert(result.hops[3].packets[2].ttl == 252) assert(result.hops[-1].index == 255) def test_traceroute_responding_target(): result = Result.get('{"af":4,"dst_addr":"220.226.205.30","dst_name":"220.226.205.30","endtime":1398334554,"from":"75.75.127.227","fw":4610,"msm_id":1000158,"msm_name":"Traceroute","paris_id":15,"prb_id":394,"proto":"UDP","result":[{"hop":1,"result":[{"from":"10.0.0.1","rtt":3.0310000000000001,"size":68,"ttl":64},{"from":"10.0.0.1","rtt":3.1930000000000001,"size":68,"ttl":64},{"from":"10.0.0.1","rtt":3.1869999999999998,"size":68,"ttl":64}]},{"hop":2,"result":[{"from":"96.120.80.5","rtt":10.606999999999999,"size":28,"ttl":254},{"from":"96.120.80.5","rtt":10.815,"size":28,"ttl":254},{"from":"96.120.80.5","rtt":10.208,"size":28,"ttl":254}]},{"hop":3,"result":[{"from":"68.86.175.213","rtt":9.7599999999999998,"size":28,"ttl":252},{"from":"68.86.175.213","rtt":15.592000000000001,"size":28,"ttl":252},{"from":"68.86.175.213","rtt":17.454000000000001,"size":28,"ttl":252}]},{"hop":4,"result":[{"from":"68.85.214.113","rtt":11.877000000000001,"size":28,"ttl":251},{"from":"68.85.214.113","rtt":11.071,"size":28,"ttl":251},{"from":"68.85.214.113","rtt":11.417999999999999,"size":28,"ttl":251}]},{"hop":5,"result":[{"from":"68.86.95.21","rtt":14.359,"size":68,"ttl":251},{"from":"68.86.95.21","rtt":24.558,"size":68,"ttl":251},{"from":"68.86.95.21","rtt":16.370000000000001,"size":68,"ttl":251}]},{"hop":6,"result":[{"from":"23.30.207.94","rtt":14.358000000000001,"size":28,"ttl":249},{"from":"23.30.207.94","rtt":14.403,"size":28,"ttl":249},{"from":"23.30.207.94","rtt":14.685,"size":28,"ttl":249}]},{"hop":7,"result":[{"from":"4.69.146.222","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1394,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"rtt":19.100000000000001,"size":140,"ttl":52},{"from":"4.69.146.222","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1394,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"rtt":19.216000000000001,"size":140,"ttl":52},{"from":"4.69.146.222","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1394,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"rtt":20.004999999999999,"size":140,"ttl":52}]},{"hop":8,"result":[{"from":"4.69.201.69","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1692,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"ittl":2,"rtt":20.114999999999998,"size":140,"ttl":52},{"from":"4.69.201.69","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1692,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"ittl":2,"rtt":20.407,"size":140,"ttl":52},{"from":"4.69.201.69","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1692,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"ittl":2,"rtt":19.105,"size":140,"ttl":52}]},{"hop":9,"result":[{"from":"4.69.134.78","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1512,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"ittl":3,"rtt":27.760000000000002,"size":140,"ttl":53},{"from":"4.69.134.78","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1512,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"ittl":3,"rtt":20.033999999999999,"size":140,"ttl":53},{"from":"4.69.134.78","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":1512,"s":1,"ttl":1}],"type":1}],"rfc4884":1,"version":2},"ittl":3,"rtt":20.065999999999999,"size":140,"ttl":53}]},{"hop":10,"result":[{"from":"4.69.155.206","rtt":18.975999999999999,"size":28,"ttl":244},{"from":"4.69.155.206","rtt":74.272999999999996,"size":28,"ttl":244},{"from":"4.69.155.206","rtt":20.582000000000001,"size":28,"ttl":244}]},{"hop":11,"result":[{"from":"4.78.132.122","rtt":22.222000000000001,"size":28,"ttl":243},{"from":"4.78.132.122","rtt":23.568000000000001,"size":28,"ttl":243},{"from":"4.78.132.122","rtt":20.062000000000001,"size":28,"ttl":243}]},{"hop":12,"result":[{"from":"85.95.25.110","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":310352,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":215.90000000000001,"size":140,"ttl":239},{"from":"85.95.25.110","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":310352,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":217.31399999999999,"size":140,"ttl":239},{"from":"85.95.25.110","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":310352,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":235.255,"size":140,"ttl":239}]},{"hop":13,"result":[{"from":"85.95.25.158","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":301856,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":93.918000000000006,"size":140,"ttl":246},{"from":"85.95.25.158","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":301856,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":93.653000000000006,"size":140,"ttl":246},{"from":"85.95.25.158","icmpext":{"obj":[{"class":1,"mpls":[{"exp":0,"label":301856,"s":1,"ttl":1}],"type":1}],"rfc4884":0,"version":2},"rtt":94.137,"size":140,"ttl":246}]},{"hop":14,"result":[{"from":"85.95.26.153","rtt":221.02600000000001,"size":28,"ttl":242},{"from":"85.95.26.153","rtt":220.42500000000001,"size":28,"ttl":242},{"from":"85.95.26.153","rtt":220.12799999999999,"size":28,"ttl":242}]},{"hop":15,"result":[{"from":"62.216.147.98","rtt":217.67699999999999,"size":68,"ttl":50},{"from":"62.216.147.98","rtt":221.37200000000001,"size":68,"ttl":50},{"from":"62.216.147.98","rtt":220.02199999999999,"size":68,"ttl":50}]},{"hop":16,"result":[{"from":"202.138.117.210","rtt":215.69499999999999,"size":28,"ttl":240},{"from":"202.138.117.210","rtt":215.68700000000001,"size":28,"ttl":240},{"from":"202.138.117.210","rtt":219.387,"size":28,"ttl":240}]},{"hop":17,"result":[{"from":"202.138.113.1","rtt":225.48099999999999,"size":28,"ttl":239},{"from":"202.138.113.1","rtt":221.18299999999999,"size":28,"ttl":239},{"from":"202.138.113.1","rtt":227.797,"size":28,"ttl":239}]},{"hop":18,"result":[{"from":"202.138.113.37","rtt":229.71799999999999,"size":28,"ttl":47},{"from":"202.138.113.37","rtt":216.155,"size":28,"ttl":47},{"from":"202.138.113.37","rtt":216.096,"size":28,"ttl":47}]},{"hop":19,"result":[{"from":"202.138.113.150","rtt":224.357,"size":28,"ttl":237},{"from":"202.138.113.150","rtt":223.726,"size":28,"ttl":237},{"from":"202.138.113.150","rtt":221.374,"size":28,"ttl":237}]},{"hop":20,"result":[{"from":"220.226.205.30","rtt":221.541,"size":68,"ttl":45},{"from":"220.226.205.30","rtt":217.10300000000001,"size":68,"ttl":45},{"from":"220.226.205.30","rtt":216.44300000000001,"size":68,"ttl":45}]}],"size":40,"src_addr":"10.0.0.7","timestamp":1398334547,"type":"traceroute"}') assert(isinstance(result, TracerouteResult)) assert(isinstance(result.hops[0], Hop)) assert(isinstance(result.hops[0].packets[0], Packet)) assert(result.af == 4) assert(result.destination_address == "220.226.205.30") assert(result.destination_name == "220.226.205.30") assert(result.end_time.isoformat() == "2014-04-24T10:15:54+00:00") print(result.end_time_timestamp, 1398334554) assert(result.end_time_timestamp == 1398334554) assert(result.origin == "75.75.127.227") assert(result.firmware == 4610) assert(result.measurement_id == 1000158) assert(result.probe_id == 394) assert(result.paris_id == 15) assert(result.protocol == TracerouteResult.PROTOCOL_UDP) assert(result.total_hops == 20) assert(result.last_median_rtt == 217.103) assert(result.destination_ip_responded is True) assert(result.last_hop_responded is True) assert(result.is_success is True) assert(result.ip_path[3][1] == "68.85.214.113") assert(result.hops[0].packets[0].destination_option_size is None) assert(result.hops[0].packets[0].hop_by_hop_option_size is None) assert(result.hops[0].packets[0].mtu is None) assert(result.hops[19].index == 20) assert(result.hops[19].packets[0].origin == "220.226.205.30") assert(result.hops[19].packets[1].rtt == 217.103) assert(result.hops[19].packets[1].size == 68) assert(result.hops[19].packets[2].ttl == 45) assert(result.hops[7].packets[0].internal_ttl == 2) assert(result.hops[7].packets[0].icmp_header.rfc4884 == 1) assert(result.hops[7].packets[0].icmp_header.version == 2) assert(result.hops[7].packets[0].icmp_header.objects == [{u"class": 1, u"mpls": [{u"exp": 0, u"label": 1692, u"s": 1, u"ttl": 1}], u"type": 1}]) assert(result.hops[1].packets[0].icmp_header is None) assert(result.hops[-1].index == 20) def test_traceroute_error(): result = Result.get('{"af":6,"dst_addr":"2001:6b0:e:3::1","dst_name":"2001:6b0:e:3:0:0:0:1","endtime":1399388948,"from":"","fw":4610,"group_id":1018508,"lts":107,"msm_id":1019825,"msm_name":"Traceroute","paris_id":5,"prb_id":82,"proto":"ICMP","result":[{"hop":1,"result":[{"err":"H","from":"2001:67c:2e8:13:fad1:11ff:fea9:dd68","rtt":2014.845,"size":88,"ttl":64},{"err":"H","from":"2001:67c:2e8:13:fad1:11ff:fea9:dd68","rtt":2995.839,"size":88,"ttl":64},{"err":"H","from":"2001:67c:2e8:13:fad1:11ff:fea9:dd68","rtt":2998.491,"size":88,"ttl":64}]}],"size":40,"src_addr":"2001:67c:2e8:13:fad1:11ff:fea9:dd68","timestamp":1399388940,"type":"traceroute"}') assert(result.total_hops == 1) assert(result.hops[0].index == 1) assert(result.hops[0].packets[0].is_error is True) assert(result.hops[0].packets[0].error_message == Packet.ERROR_CONDITIONS["H"]) assert(result.hops[0].packets[1].is_error is True) assert(result.hops[0].packets[1].error_message == Packet.ERROR_CONDITIONS["H"]) assert(result.hops[0].packets[2].is_error is True) assert(result.hops[0].packets[2].error_message == Packet.ERROR_CONDITIONS["H"]) def test_traceroute_error_unreachable(): result = Result.get('{"af":6,"dst_addr":"2001:6b0:e:3::1","dst_name":"2001:6b0:e:3:0:0:0:1","endtime":1398180530,"from":"","fw":4610,"group_id":1018508,"lts":10065,"msm_id":1019825,"msm_name":"Traceroute","paris_id":14,"prb_id":82,"proto":"ICMP","result":[{"error":"connect failed: Network is unreachable","hop":1}],"size":40,"src_addr":"2001:67c:2e8:13:fad1:11ff:fea9:dd68","timestamp":1398180530,"type":"traceroute"}') assert(result.total_hops == 1) assert(result.hops[0].index == 1) assert(result.hops[0].is_error is True) assert(result.hops[0].error_message == "connect failed: Network is unreachable") assert(len(result.hops[0].packets) == 0) def test_traceroute_v6_mtu(): result = Result.get('{"af":6,"dst_addr":"2a03:8180:1001:b2:45::3","dst_name":"2a03:8180:1001:b2:45:0:0:3","endtime":1400582566,"from":"","fw":4610,"group_id":1666033,"msm_id":1666033,"msm_name":"Traceroute","paris_id":1,"prb_id":2463,"proto":"ICMP","result":[{"hop":1,"result":[{"from":"2001:470:d04f:12::18","mtu":1500,"rtt":5.1260000000000003,"size":1232,"ttl":64},{"x":"*"},{"err":"H","from":"2001:470:d04f:12::18","rtt":3011.8739999999998,"size":1232,"ttl":64},{"err":"H","from":"2001:470:d04f:12::18","rtt":3011.8110000000001,"size":1232,"ttl":64},{"err":"H","from":"2001:470:d04f:12::18","rtt":3011.8690000000001,"size":1232,"ttl":64}]},{"hop":2,"result":[{"err":"H","from":"2001:470:d04f:12::18","ittl":2,"rtt":3011.6619999999998,"size":1232,"ttl":64},{"err":"H","from":"2001:470:d04f:12::18","ittl":2,"rtt":3011.877,"size":1232,"ttl":64},{"err":"H","from":"2001:470:d04f:12::18","ittl":2,"rtt":3011.866,"size":1232,"ttl":64},{"err":"H","from":"2001:470:d04f:12::18","ittl":2,"rtt":3012.1300000000001,"size":1232,"ttl":64},{"err":"H","from":"2001:470:d04f:12::18","ittl":2,"rtt":3012.1700000000001,"size":1232,"ttl":64}]}],"size":2000,"src_addr":"2001:470:d04f:12::18","timestamp":1400582538,"type":"traceroute"}') assert(result.hops[0].packets[0].mtu == 1500) def test_traceroute_v6_options(): result = Result.get('{"af":6,"dst_addr":"2a00:1450:4013:c01::5e","dst_name":"2a00:1450:4013:c01:0:0:0:5e","endtime":1400087957,"from":"2601:6:7980:584:6666:b3ff:feb0:f3b8","fw":4610,"group_id":1665356,"msm_id":1665357,"msm_name":"Traceroute","paris_id":1,"prb_id":14748,"proto":"ICMP","result":[{"hop":1,"result":[{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":5.0170000000000003,"size":608,"ttl":64},{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":4.4960000000000004,"size":608,"ttl":64},{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":4.9770000000000003,"size":608,"ttl":64},{"x":"*"},{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":4.8120000000000003,"size":608,"ttl":64},{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":4.556,"size":608,"ttl":64},{"x":"*"},{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":4.9500000000000002,"size":608,"ttl":64},{"x":"*"},{"dstoptsize":512,"from":"2601:6:7980:584::1","rtt":4.5,"size":608,"ttl":64}]},{"hop":2,"result":[{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":17.681999999999999,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":13.93,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":12.875,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":11.496,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":11.692,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":13.476000000000001,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":11.685,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":15.076000000000001,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":14.548999999999999,"size":608,"ttl":63},{"dstoptsize":512,"from":"2001:558:4023:f6::1","rtt":11.723000000000001,"size":608,"ttl":63}]},{"hop":3,"result":[{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":13.426,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":13.311999999999999,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":14.772,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":12.185,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":13.241,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":15.148999999999999,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":12.010999999999999,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":11.635,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":13.837999999999999,"size":608,"ttl":62},{"dstoptsize":512,"from":"2001:558:202:82::1","rtt":13.212,"size":608,"ttl":62}]},{"hop":4,"result":[{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.193,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.891,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.178000000000001,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.457000000000001,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.097,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":12.823,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.66,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.865,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":13.714,"size":608,"ttl":61},{"dstoptsize":512,"from":"2001:558:200:8f::1","rtt":15.621,"size":608,"ttl":61}]},{"hop":5,"result":[{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":19.004000000000001,"size":608,"ttl":60},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":21.626000000000001,"size":608,"ttl":60},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":21.167999999999999,"size":608,"ttl":60},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":17.995999999999999,"size":608,"ttl":60},{"x":"*"},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":19.061,"size":608,"ttl":60},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":17.544,"size":608,"ttl":60},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":18.108000000000001,"size":608,"ttl":60},{"dstoptsize":512,"from":"2001:558:200:175::1","rtt":17.172000000000001,"size":608,"ttl":60},{"x":"*"}]},{"hop":6,"result":[{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":23.879999999999999,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":25.186,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":21.422999999999998,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":25.553000000000001,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":25.783000000000001,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":26.172999999999998,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":25.032,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":26.071999999999999,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":25.173999999999999,"size":608,"ttl":59},{"dstoptsize":512,"from":"2001:558:200:11d::1","rtt":25.318999999999999,"size":608,"ttl":59}]},{"hop":7,"result":[{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":31.378,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":29.427,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":29.52,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":30.445,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":28.565000000000001,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":29.602,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":30.321999999999999,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":28.719999999999999,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":29.369,"size":608,"ttl":58},{"dstoptsize":512,"from":"2001:558:0:f76e::1","rtt":29.747,"size":608,"ttl":58}]},{"hop":8,"result":[{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":30.334,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":27.571999999999999,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":31.545999999999999,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":27.419,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":29.584,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":27.41,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":31.577999999999999,"size":608,"ttl":57},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":28.866,"size":608,"ttl":57},{"x":"*"},{"dstoptsize":512,"from":"2001:558:0:f8d7::2","rtt":30.077999999999999,"size":608,"ttl":57}]},{"hop":9,"result":[{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":10,"result":[{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":11,"result":[{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":12,"result":[{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":13,"result":[{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"}]},{"hop":255,"result":[{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"},{"x":"*"}]}],"size":40,"src_addr":"2601:6:7980:584:6666:b3ff:feb0:f3b8","timestamp":1400087690,"type":"traceroute"}') assert(result.hops[0].packets[0].destination_option_size == 512) assert(result.hops[0].packets[1].destination_option_size == 512) assert(result.hops[0].packets[2].destination_option_size == 512) assert(result.hops[0].packets[3].destination_option_size is None) result = Result.get('{"af":6,"dst_addr":"2a02:d28:667::2","dst_name":"2a02:d28:667:0:0:0:0:2","endtime":1400589952,"from":"2a02:d28:667:1::2","fw":4620,"group_id":1666051,"msm_id":1666051,"msm_name":"Traceroute","paris_id":1,"prb_id":6021,"proto":"UDP","result":[{"hop":1,"result":[{"from":"2a02:d28:667:1::1","hbhoptsize":256,"rtt":2.669,"size":352,"ttl":64},{"from":"2a02:d28:667:1::1","hbhoptsize":256,"rtt":0.27200000000000002,"size":352,"ttl":64},{"from":"2a02:d28:667:1::1","hbhoptsize":256,"rtt":2.2309999999999999,"size":352,"ttl":64}]},{"hop":2,"result":[{"from":"2a02:d28:5580:1::d1","hbhoptsize":256,"rtt":64.810000000000002,"size":352,"ttl":61},{"from":"2a02:d28:5580:1::d1","hbhoptsize":256,"rtt":76.120000000000005,"size":352,"ttl":63},{"from":"2a02:d28:5580:1::d1","hbhoptsize":256,"rtt":83.963999999999999,"size":352,"ttl":61}]},{"hop":3,"result":[{"from":"2a02:d28:5580::1:b9","hbhoptsize":256,"rtt":100.01000000000001,"size":352,"ttl":62},{"from":"2a02:d28:5580::1:b9","hbhoptsize":256,"rtt":88.451999999999998,"size":352,"ttl":62},{"from":"2a02:d28:5580::1:b9","hbhoptsize":256,"rtt":88.390000000000001,"size":352,"ttl":62}]},{"hop":4,"result":[{"from":"2a02:d28:5580:1::c1","hbhoptsize":256,"rtt":88.792000000000002,"size":352,"ttl":61},{"from":"2a02:d28:5580:1::c1","hbhoptsize":256,"rtt":88.882000000000005,"size":352,"ttl":61},{"from":"2a02:d28:5580:1::c1","hbhoptsize":256,"rtt":87.719999999999999,"size":352,"ttl":61}]},{"hop":5,"result":[{"from":"2a02:d28:667::2","hbhoptsize":256,"rtt":90.457999999999998,"size":352,"ttl":60},{"from":"2a02:d28:667::2","hbhoptsize":256,"rtt":91.408000000000001,"size":352,"ttl":60},{"from":"2a02:d28:667::2","hbhoptsize":256,"rtt":85.784999999999997,"size":352,"ttl":60}]}],"size":40,"src_addr":"2a02:d28:667:1::2","timestamp":1400589951,"type":"traceroute"}') assert(result.hops[0].packets[0].hop_by_hop_option_size is 256) assert(result.hops[0].packets[1].hop_by_hop_option_size is 256) assert(result.hops[0].packets[2].hop_by_hop_option_size is 256) def test_traceroute_lts(): result = Result.get('{"lts":2029,"size":40,"group_id":1000157,"from":"192.172.226.243","dst_name":"121.244.76.25","fw":4650,"proto":"UDP","af":4,"msm_name":"Traceroute","prb_id":319,"result":[{"result":[{"rtt":1.891,"ttl":254,"from":"192.172.226.252","size":28},{"rtt":34.727,"ttl":254,"from":"192.172.226.252","size":28},{"rtt":1.731,"ttl":254,"from":"192.172.226.252","size":28}],"hop":1},{"result":[{"rtt":1.726,"ttl":253,"from":"192.12.207.61","size":28},{"rtt":1.724,"ttl":253,"from":"192.12.207.61","size":28},{"rtt":1.72,"ttl":253,"from":"192.12.207.61","size":28}],"hop":2},{"result":[{"rtt":1.72,"ttl":253,"from":"137.164.23.129","size":28},{"rtt":1.735,"ttl":253,"from":"137.164.23.129","size":28},{"rtt":1.724,"ttl":253,"from":"137.164.23.129","size":28}],"hop":3},{"result":[{"rtt":13.136,"ttl":252,"from":"137.164.47.110","size":68},{"rtt":10.883,"ttl":252,"from":"137.164.47.110","size":68},{"rtt":13.087,"ttl":252,"from":"137.164.47.110","size":68}],"hop":4},{"result":[{"rtt":15.208,"ttl":251,"from":"137.164.46.57","size":68},{"rtt":12.571,"ttl":251,"from":"137.164.46.57","size":68},{"rtt":14.545,"ttl":251,"from":"137.164.46.57","size":68}],"hop":5},{"result":[{"rtt":11.037,"ttl":250,"from":"137.164.47.136","size":28},{"rtt":10.957,"ttl":250,"from":"137.164.47.136","size":28},{"rtt":11.011,"ttl":250,"from":"137.164.47.136","size":28}],"hop":6},{"result":[{"rtt":11.075,"ttl":249,"from":"4.59.48.177","size":28},{"rtt":11.032,"ttl":249,"from":"4.59.48.177","size":28},{"rtt":69.194,"ttl":249,"from":"4.59.48.177","size":28}],"hop":7},{"result":[{"rtt":11.25,"ttl":248,"from":"4.69.144.80","size":28},{"rtt":11.141,"ttl":248,"from":"4.69.144.80","size":28},{"rtt":11.177,"ttl":248,"from":"4.69.144.80","size":28}],"hop":8},{"result":[{"rtt":11.316,"ttl":247,"from":"4.68.62.118","size":28},{"rtt":11.243,"ttl":247,"from":"4.68.62.118","size":28},{"rtt":11.238,"ttl":247,"from":"4.68.62.118","size":28}],"hop":9},{"result":[{"rtt":37.808,"ttl":245,"from":"64.86.252.38","size":28},{"rtt":37.811,"ttl":245,"from":"64.86.252.38","size":28},{"rtt":37.768,"ttl":245,"from":"64.86.252.38","size":28}],"hop":10},{"result":[{"rtt":277.064,"ttl":232,"from":"66.198.144.2","size":28},{"rtt":276.963,"ttl":232,"from":"66.198.144.2","size":28},{"rtt":276.92,"ttl":232,"from":"66.198.144.2","size":28}],"hop":11},{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":12},{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":13},{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":14},{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":15},{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":16},{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":255}],"timestamp":1406561027,"src_addr":"192.172.226.243","paris_id":5,"endtime":1406561047,"type":"traceroute","dst_addr":"121.244.76.25","msm_id":1000157}') assert(result.seconds_since_sync == 2029) def test_traceroute_last_hop_responded_vs_destination_ip_responded(): result = Result.get('{"af":6,"dst_addr":"2a00:1450:4001:808::1010","dst_name":"2a00:1450:4001:808::1010","endtime":1414685936,"from":"2001:6c8:3f00:abe:280:a3ff:fe91:4252","fw":4660,"group_id":1772418,"lts":110,"msm_id":1772418,"msm_name":"Traceroute","paris_id":1,"prb_id":4978,"proto":"UDP","result":[{"hop":1,"result":[{"from":"2001:6c8:3f00:abe::1","rtt":2.399,"size":96,"ttl":63},{"from":"2001:6c8:3f00:abe::1","rtt":2.199,"size":96,"ttl":63},{"from":"2001:6c8:3f00:abe::1","rtt":2.136,"size":96,"ttl":63}]},{"hop":2,"result":[{"from":"2001:6c8:41:100:0:10:3:1","rtt":22.533,"size":96,"ttl":62},{"from":"2001:6c8:41:100:0:10:3:1","rtt":22.131,"size":96,"ttl":62},{"from":"2001:6c8:41:100:0:10:3:1","rtt":22.54,"size":96,"ttl":62}]},{"hop":3,"result":[{"from":"2001:6f0:40::3a","rtt":33.808,"size":96,"ttl":61},{"from":"2001:6f0:40::3a","rtt":33.815,"size":96,"ttl":61},{"from":"2001:6f0:40::3a","rtt":34.074,"size":96,"ttl":61}]},{"hop":4,"result":[{"from":"2001:6f0:81:100::6:2","rtt":34.335,"size":96,"ttl":60},{"from":"2001:6f0:81:100::6:2","rtt":34.33,"size":96,"ttl":60},{"from":"2001:6f0:81:100::6:2","rtt":34.135,"size":96,"ttl":60}]},{"hop":5,"result":[{"from":"2001:4860::1:0:26eb","rtt":34.559,"size":96,"ttl":59},{"from":"2001:4860::1:0:26eb","rtt":34.638,"size":96,"ttl":59},{"from":"2001:4860::1:0:26eb","rtt":49.453,"size":96,"ttl":59}]},{"hop":6,"result":[{"from":"2001:4860::8:0:4fc8","rtt":35.123,"size":96,"ttl":57},{"from":"2001:4860::8:0:4fc8","rtt":34.621,"size":96,"ttl":57},{"from":"2001:4860::8:0:4fc8","rtt":34.896,"size":96,"ttl":57}]},{"hop":7,"result":[{"from":"2001:4860::8:0:672e","rtt":49.557,"size":96,"ttl":56},{"from":"2001:4860::8:0:672e","rtt":50.057,"size":96,"ttl":56},{"from":"2001:4860::8:0:672e","rtt":50.39,"size":96,"ttl":56}]},{"hop":8,"result":[{"from":"2001:4860::8:0:5039","rtt":50.039,"size":96,"ttl":57},{"from":"2001:4860::8:0:5039","rtt":50.078,"size":96,"ttl":57},{"from":"2001:4860::8:0:5039","rtt":50.061,"size":96,"ttl":57}]},{"hop":9,"result":[{"from":"2001:4860::1:0:4ca2","rtt":52.175,"size":96,"ttl":59},{"from":"2001:4860::1:0:4ca2","rtt":58.49,"size":96,"ttl":59},{"from":"2001:4860::1:0:4ca2","rtt":55.845,"size":96,"ttl":59}]},{"hop":10,"result":[{"from":"2001:4860:0:1::6ef","rtt":50.311,"size":96,"ttl":58},{"x":"*"},{"x":"*"}]},{"hop":11,"result":[{"from":"2a00:1450:8000:3d::3","rtt":52.233,"size":96,"ttl":57},{"from":"2a00:1450:8000:3d::3","rtt":50.576,"size":96,"ttl":57},{"from":"2a00:1450:8000:3d::3","rtt":50.277,"size":96,"ttl":57}]}],"size":48,"src_addr":"2001:6c8:3f00:abe:280:a3ff:fe91:4252","timestamp":1414685926,"type":"traceroute"}') assert(result.destination_ip_responded is False) assert(result.last_hop_responded is True) def test_traceroute_with_late_packets(): # Older firmwares result = Result.get('{"lts":-1,"size":40,"from":"185.60.176.3","dst_name":"78.46.48.134","fw":4720,"proto":"UDP","af":4,"msm_name":"Traceroute","prb_id":10834,"result":[{"result":[{"x":"*"},{"x":"*"},{"x":"*"}],"hop":1},{"result":[{"late":4,"ttl":63,"from":"192.168.14.253","size":68},{"x":"*"},{"late":5,"ttl":63,"from":"192.168.14.253","size":68},{"x":"*"},{"late":6,"ttl":63,"from":"192.168.14.253","size":68},{"x":"*"}],"hop":2},{"result":[{"late":7,"ttl":253,"from":"141.105.161.184","size":28},{"x":"*"},{"late":8,"ttl":253,"from":"141.105.161.184","size":28},{"x":"*"},{"late":9,"ttl":253,"from":"141.105.161.184","size":28},{"x":"*"}],"hop":3},{"result":[{"late":10,"ttl":252,"from":"141.105.161.176","size":28},{"x":"*"},{"late":11,"ttl":252,"from":"141.105.161.176","size":28},{"x":"*"},{"late":12,"ttl":252,"from":"141.105.161.176","size":28},{"x":"*"}],"hop":4},{"result":[{"late":13,"ttl":251,"from":"94.201.50.45","size":68},{"x":"*"},{"late":14,"ttl":251,"from":"94.201.50.45","size":68},{"x":"*"},{"late":15,"ttl":251,"from":"94.201.50.45","size":68},{"x":"*"}],"hop":5},{"result":[{"late":16,"ittl":244,"from":"78.46.48.134","ttl":53,"size":68},{"x":"*"},{"late":17,"ittl":244,"from":"78.46.48.134","ttl":53,"size":68},{"x":"*"},{"late":18,"ittl":244,"from":"78.46.48.134","ttl":53,"size":68},{"x":"*"}],"hop":255}],"timestamp":1447330668,"src_addr":"185.60.176.3","paris_id":10,"endtime":1447330686,"type":"traceroute","dst_addr":"78.46.48.134","msm_id":5017}') assert(len(result.hops[0].packets) == 3) assert(result.hops[0].packets[0].origin is None) assert(result.hops[0].packets[0].rtt is None) for packet in result.hops[1].packets: print(packet.raw_data) assert(len(result.hops[1].packets) == 3) assert(result.hops[1].packets[0].origin is None) assert(result.hops[1].packets[0].rtt is None) assert(result.is_success is False) # Newer firmwares # No sample available yet def test_last_responded_hop_with_error_packets(): """" Case where traceroute has a single hop and all of its packets have error in them. """ result = Result.get({'lts': 117, 'msm_id': 3059023, 'endtime': 1449152831, 'from': '2001:470:1883:1:6666:b3ff:feb0:dcda', 'dst_name': '2001:980:1284:10:beee:7bff:fe87:9eda', 'fw': 4720, 'timestamp': 1449152831, 'proto': 'ICMP', 'paris_id': 1, 'prb_id': 14468, 'af': 6, 'result': [{'result': [{'rtt': 0.714, 'size': 96, 'from': '2001:470:1883:1::1', 'err': 'N', 'ttl': 64}, {'rtt': 0.495, 'size': 96, 'from': '2001:470:1883:1::1', 'err': 'N', 'ttl': 64}, {'rtt': 0.48, 'size': 96, 'from': '2001:470:1883:1::1', 'err': 'N', 'ttl': 64}], 'hop': 1}], 'dst_addr': '2001:980:1284:10:beee:7bff:fe87:9eda', 'src_addr': '2001:470:1883:1:6666:b3ff:feb0:dcda', 'group_id': 3059023, 'type': 'traceroute', 'msm_name': 'Traceroute', 'size': 48}) assert(len(result.hops[0].packets) == 3) assert(result.last_hop_responded is True) assert(result.is_success is False) def test_is_success_with_error_packets(): """" Case where traceroute has a single hop and all of its packets have error in them. """ result = Result.get({'lts': 117, 'msm_id': 3059023, 'endtime': 1449152831, 'from': '2001:470:1883:1:6666:b3ff:feb0:dcda', 'dst_name': '2001:980:1284:10:beee:7bff:fe87:9eda', 'fw': 4720, 'timestamp': 1449152831, 'proto': 'ICMP', 'paris_id': 1, 'prb_id': 14468, 'af': 6, 'result': [{'result': [{'rtt': 0.714, 'size': 96, 'from': '2001:470:1883:1::1', 'err': 'N', 'ttl': 64}, {'rtt': 0.495, 'size': 96, 'from': '2001:470:1883:1::1', 'err': 'N', 'ttl': 64}, {'rtt': 0.48, 'size': 96, 'from': '2001:470:1883:1::1', 'err': 'N', 'ttl': 64}], 'hop': 1}], 'dst_addr': '2001:980:1284:10:beee:7bff:fe87:9eda', 'src_addr': '2001:470:1883:1:6666:b3ff:feb0:dcda', 'group_id': 3059023, 'type': 'traceroute', 'msm_name': 'Traceroute', 'size': 48}) assert(len(result.hops[0].packets) == 3) assert(result.is_success is False) assert(result.last_hop_errors == ['Network unreachable', 'Network unreachable', 'Network unreachable']) def test_missing_dst_addr(): """"Case where traceroute misses dst_addr key.""" result = Result.get({"af": 4, "dst_name": "syndication.exoclick.com", "endtime": 1446563590, "from": "89.216.30.6", "fw": 4720, "group_id": 2906346, "lts": 80, "msm_id": 2906346, "msm_name": "Traceroute", "paris_id": 0, "prb_id": 22586, "proto": "ICMP", "result": [{"error": "name resolution failed: non-recoverable failure in name resolution (1)"}], "size": 48, "timestamp": 1446563590, "type": "traceroute"}) assert(result.destination_address is None) assert(result.is_success is False) ripe-atlas-sagan-1.3.1/tests/wifi.py000066400000000000000000000071671405365472700173460ustar00rootroot00000000000000# Copyright (c) 2016 RIPE NCC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from ripe.atlas.sagan import Result from ripe.atlas.sagan.wifi import WiFiResult def test_wifi(): raw_data = { "bundle": 1463495978, "from": "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0", "fw": "4733", "group_id": 1021275, "msm_id": 1021275, "msm_name": "WiFi", "prb_id": 105, "timestamp": 1463495978, "type": "wifi", "wpa_supplicant": { "address": "ea:de:27:69:e6:f0", "bssid": "08:ea:44:3b:6d:14", "connect-time": "2", "group_cipher": "CCMP", "id": "0", "ip_address": "193.0.10.126", "key_mgmt": "WPA2-PSK", "mode": "station", "pairwise_cipher": "CCMP", "ssid": "guestnet", "wpa_state": "COMPLETED" } } result = Result.get(raw_data) assert(isinstance(result, WiFiResult)) assert(result.bundle == 1463495978) assert(result.origin == "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0") assert(result.firmware == 4733) assert(result.group_id == 1021275) assert(result.wpa_supplicant.address == "ea:de:27:69:e6:f0") assert(result.wpa_supplicant.bssid == "08:ea:44:3b:6d:14") assert(result.wpa_supplicant.connect_time == "2") assert(result.wpa_supplicant.group_cipher == "CCMP") assert(result.wpa_supplicant.wpa_supplicant_id == "0") assert(result.wpa_supplicant.ip_address == "193.0.10.126") assert(result.wpa_supplicant.key_management == "WPA2-PSK") assert(result.wpa_supplicant.mode == "station") assert(result.wpa_supplicant.pairwise_cipher == "CCMP") assert(result.wpa_supplicant.ssid == "guestnet") assert(result.wpa_supplicant.wpa_state == "COMPLETED") def test_wifi_error(): raw_data = { "bundle": 1463493022, "error": "wpa timeout", "from": "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0", "fw": "4733", "group_id": 1021275, "msm_id": 1021275, "msm_name": "WiFi", "prb_id": 105, "timestamp": 1463493023, "type": "wifi", "wpa_supplicant": {"connect-time": "11"} } result = Result.get(raw_data) assert(isinstance(result, WiFiResult)) assert(result.bundle == 1463493022) assert(result.origin == "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0") assert(result.firmware == 4733) assert(result.group_id == 1021275) assert(result.created_timestamp == 1463493023) assert(result.wpa_supplicant.address is None) assert(result.wpa_supplicant.bssid is None) assert(result.wpa_supplicant.connect_time == "11") assert(result.wpa_supplicant.group_cipher is None) assert(result.wpa_supplicant.wpa_supplicant_id is None) assert(result.wpa_supplicant.ip_address is None) assert(result.wpa_supplicant.key_management is None) assert(result.wpa_supplicant.mode is None) assert(result.wpa_supplicant.pairwise_cipher is None) assert(result.wpa_supplicant.ssid is None) assert(result.wpa_supplicant.wpa_state is None) ripe-atlas-sagan-1.3.1/tox.ini000066400000000000000000000001301405365472700161660ustar00rootroot00000000000000[tox] envlist=py27,py35,py36,py37 [testenv] commands=python setup.py test [] deps=nose