Data Science, Machine Learning, Natural Language Processing, Text Analysis, Recommendation Engine, R, Python
Thursday, 24 August 2017
Python Bytes: #40 Packet Manipulation with Scapy
<p>We have guest hosts filling in for Michael while he is on vacation. This week we have <a href="https://twitter.com/ericchou">Eric Chou</a>, author of the book “Mastering Python Networking” and a self-proclaimed Network Automation Nerd. </p> <p><strong>Eric #1:</strong> <a href="http://ift.tt/1TlSQC5"><strong>DevOps Automation Tool: Ansible</strong></a></p> <ul> <li>DevOps Automation framework written in Python, code hosted on <a href="http://ift.tt/12nDANp">GitHub</a>.</li> <li><a href="http://ift.tt/1swjNmH">Top 10 OpenSource projects in 2014 by OpenSource.com</a>, along with Docker, Kubernetes, Apache Hadoop, OpenStack, and OpenDaylight, etc. </li> <li>Excellent <a href="http://ift.tt/2vYQrte">documentation</a> for all modules. </li> <li>Agentless, ‘networking vendor’ friendly, execute code locally that interacts with the device via SSH and API. </li> <li><a href="http://ift.tt/2wHuU8d">Lots of Network modules</a>, including Cisco, Juniper, Arista, etc. In fact, you can find Cisco and Juniper testimonial on the Ansible site. </li> <li>Easy to learn and extend if you already know a little bit about Python, YAML, and Jinja2. </li> </ul> <p><strong>Brian #2:</strong> <a href="http://ift.tt/2uXBBzi"><strong>Python Practices for Efficient Code: Performance, Memory, and Usability</strong></a></p> <p>(I’m too opinionated to leave out my thoughts when covering this article, even though it’s very well written and I mean no disrespect to Satwik Kansal)</p> <ol> <li>Try not to blow off memory <ul> <li>use generators to calculate large sets of results</li> <li>for big number crunching, use <a href="http://www.numpy.org/">numpy</a></li> <li>Use format instead of + for large strings. (or f-strings - Brian)</li> <li>Use slots for classes (psshh, use attrs - Brian)</li> </ul></li> <li>Python 2 or 3 <ul> <li>Write code compatible with both. (disagree, use 3 unless you can’t for a very good reason, then write code that’s easy to convert to 3 later. - Brian)</li> </ul></li> <li>Write Beautiful code because “The first impression is the last impression." <ul> <li>follow style guides</li> <li>use static analysis tools. Recommended using something called coala that’s installed as “coala-bears.</li> <li>(Brian: Maintenance cost is a real thing. Make your code look good because it’s cheaper in the long run. Use pycodestyle, pydocstyle, flake8, and if using sublime, use <a href="http://ift.tt/1irIlXy">Flake8Lint</a>) </li> </ul></li> <li>Speed up your performance <ul> <li>Multiprocess, not Multi-thread</li> </ul></li> <li>Analyzing your code <ul> <li>Use cProfile, memory_profiler, objgraph, resource</li> </ul></li> <li>Testing and CI <ul> <li>nose or pytest or doctest</li> <li>(Brian: BTW, I really appreciate the links to pythontesting.net for tutorials on these.)</li> <li>(Brian: No. Use pytest)</li> <li>measure coverage and and try for 100%</li> <li>(Brian: No. use coverage to be alerted of sudden changes, and of code that possibly needs more testing and/or deleted)</li> </ul></li> </ol> <p><strong>Eric #3:</strong> <a href="http://ift.tt/I4NpPk"><strong>Packet Manipulation Program: Scapy</strong></a></p> <ul> <li>Free Python-based interactive packet manipulation program and library, <a href="http://ift.tt/1OxiXkv">GitHub</a>. </li> <li>Craft the packet from the ground up, you can use it to decode packets or craft packets. </li> <li>You are in control instead of limited to what the creator of the tool can imagine, i.e. hping3, curl. </li> <li><a href="http://ift.tt/Mm0h5V">Can be used together with the Python interpreter</a>. </li> <li>Particularly useful for network security <ul> <li>Crafting common attacks: malformed packets (such as IP version 3), Ping of Death (large paylaod), Land Attack (redirect the client response back to the client itself) for denial-of-service. </li> <li>Penetration Testing (TCP port scan) and Fuzzing by providing invalid, unexpected, or random data. </li> </ul></li> </ul> <p><strong>Brian #4:</strong> <a href="http://ift.tt/2vgtHVl"><strong>Using Headless Chrome with Selenium</strong></a></p> <ul> <li>Miguel Grinberg quick demo of using headless chrome with selenium and unittest.</li> <li>(Brian: Eventually I’ll get Miguel to use pytest more.)</li> <li>Replace the normal Firefox with Chrome in the webdriver of Selenium, and passing a ‘headless’ argument to make it so the window doesn’t keep popping up and down when testing.</li> </ul> <p><strong>Eric</strong> <strong>#5:</strong> <a href="http://ift.tt/pORmK8"><strong>Graph Visualization with Graphviz</strong></a></p> <ul> <li>Open Source graph visualization software. </li> <li>Perfect for graphing the large datacenter topology automatically or any other network diagrams. </li> <li>Extensive <a href="http://ift.tt/1eCi9HV">documentation</a> and <a href="http://ift.tt/1mRb9Og">gallery of examples</a>. </li> <li>Did I mention this is ‘automatible’? Thus avoid drifts between reality and actual network. </li> <li>Python package <a href="http://ift.tt/1uUqnHf">graphviz</a> (lower case g) for Graphviz integration. </li> </ul> <p><strong>Brian</strong> <strong>#6:</strong> <a href="http://ift.tt/2hm82p2"><strong>PyCascades CFP still open until the 28th</strong></a></p> <ul> <li>Python conference in Vancouver, BC.</li> <li>Talks Jan 22, 23, Sprints Jan 24th</li> <li>Speakers get free admission. Talks are all 25 min slots. No Q&A after talks in front of full audience, but speakers will hang out up front for a few minutes for individual questions</li> <li>I’m going to submit at least one proposal. But I’m kinda swamped this week, so the proposal will unfortunately be rushed.</li> </ul> <p><strong>Extra Eric:</strong></p> <ul> <li><a href="http://ift.tt/2wI3NKa">Mastering Python Networking</a> book </li> <li>Network Labs: <a href="http://ift.tt/2vhZTEq">Cisco Virtual Internet Routing Lab (VIRL)</a>, <a href="http://ift.tt/1mD72p5">Cisco DevNet</a>, <a href="https://www.gns3.com/">GNS3 (Graphic Network Simulator)</a>. </li> </ul> <p><strong>Extra Brian:</strong></p> <ul> <li>Copy editing and final testing with most recent Python and pytest done for <a href="http://ift.tt/2nL8dbT">Python Testing with pytest</a></li> </ul>
No comments:
Post a Comment