├── README.md
├── bookmarks.txt
├── graphs.md
├── index.html
├── license.txt
├── networkmap
├── __init__.py
├── __main__.py
├── errors.py
├── netgrapher.py
├── parsers.py
└── test_parsers.py
├── notes.md
├── requirements.txt
├── samples
├── arp
│ ├── linux_arp.txt
│ ├── openbsd_arp.txt
│ ├── windows_7_arp.txt
│ └── windows_7_arp2.txt
├── ifconfig
│ ├── linux_ifconfig.txt
│ └── linux_ip_addr.txt
├── ipconfig
│ └── windows_7_ipconfig.txt
├── route
│ ├── linux_ip_route.txt
│ ├── linux_netstat.txt
│ ├── linux_route.txt
│ └── windows_7_route_print.txt
└── traceroute
│ └── linux_traceroute.txt
└── simplenetwork.png
/README.md:
--------------------------------------------------------------------------------
1 | Post-exploitation network mapping
2 | =================================
3 |
4 | The purpose of this tool is to produce a network diagram by collating network information gathered on remote hosts.
5 |
6 | Example:
7 |
8 | * Log on host A as any user
9 | * Dump some network information e.g. routing table, ARP table, traceroute
10 | * Feed the dumps to this tool
11 | * Go to another host
12 | * Dump network information
13 |
14 | ...rinse, repeat
15 |
16 | * Ultimately, this tool produces a network diagram showing all hosts reachable
17 | from your compromised nodes.
18 |
19 | Result (work in progress, but you get the idea):
20 |
21 | 
22 |
23 | Please note that this is WORK IN PROGRESS and it needs some work to parse e.g. routing tables, etc. If you feel like helping, please take a look [here](https://github.com/lorenzog/NetworkMap/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
24 |
25 | Installation
26 | ------------
27 |
28 | You'll need a fairly recent Python version with setuptools.
29 |
30 | 1. Set up a virtualenv:
31 |
32 | virtualenv venv
33 | source venv/bin/activate
34 |
35 | 2. Install the required libraries:
36 |
37 | pip install -r requirements.txt
38 |
39 |
40 | Usage
41 | -----
42 |
43 | Run the tool passing the path of a network dump on the command line:
44 |
45 | python networkmap samples/arp/windows_7_arp.txt
46 |
47 | Then every subsequent run will grow the knowledge about the network (saved into the `networkmap.json` file).
48 |
49 | # note that with traceroute you need to specify the IP of the host
50 | python networkmap samples/traceroute/linux_traceroute.txt --ip 1.2.3.4
51 |
52 | #### How to see the result
53 |
54 | Two methods:
55 |
56 | 1. Use the `-H` switch to automatically run Python's `SimpleHTTPServer` after each successful run (don't forget to point your browser to `http://localhost:8000`):
57 |
58 | python networkmap samples/arp/linux_arp.txt --ip 1.2.3.4 -H
59 |
60 | Or,
61 |
62 | 2. If you just want to serve the content of this directory use this command:
63 |
64 | python -m SimpleHTTPServer
65 |
66 | **WARNING** don't run the second method on an untrusted network as it will serve **the entire content of the local directory** to **ANYONE** as it listens to 0.0.0.0 rather than 127.0.0.1.
67 |
68 |
69 | ### Installing GraphViz
70 |
71 | If you want to automatically generate graphs (by default: yes) then you'll need
72 | pygraphviz installed. For debian-based systems:
73 |
74 | apt-get install pkg-config libgraphviz-dev graphviz-dev graphviz libgraphviz
75 |
76 | For RPM based systems:
77 |
78 | yum install graphviz graphviz-devel
79 |
80 |
81 | #### Weird errors when installing pygraphviz
82 |
83 | ##### Undefined symbol: Agundirected
84 |
85 | If you get a similar error to this one on a Debian-based system:
86 |
87 | File "/home/user/dev/NetworkMap/venv/local/lib/python2.7/site-packages/pygraphviz/graphviz.py", line 24, in swig_import_helper
88 | _mod = imp.load_module('_graphviz', fp, pathname, description)
89 | ImportError: /home/user/dev/NetworkMap/venv/local/lib/python2.7/site-packages/pygraphviz/_graphviz.so: undefined symbol: Agundirected
90 |
91 | Then fix it like that:
92 |
93 | pip uninstall graphviz
94 | pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/"
95 |
96 | Source: http://stackoverflow.com/questions/32885486/pygraphviz-importerror-undefined-symbol-agundirected
97 |
98 | ##### redhat-hardened-cc1 missing
99 |
100 | If you get this error on a Fedora-based system:
101 |
102 | gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
103 |
104 | You need to install redhat-rpm-config. Source: http://stackoverflow.com/a/34641068/204634
105 |
106 |
107 | Possible alternatives
108 | ---------------------
109 |
110 | P2NMAP (it's a book, comes with source code): https://python-forensics.org/p2nmap/
111 |
112 | #### Future:
113 |
114 | * Dump into Excel spreadsheet or SQL database?
115 | * Import into Microsoft Visio? https://support.office.com/en-gb/article/Create-a-detailed-network-diagram-by-using-external-data-in-Visio-Professional-1d43d1a0-e1ac-42bf-ad32-be436411dc08#bm2
116 |
117 | Misc notes
118 | ----------
119 |
120 | * Graphviz can also do clustering? http://www.graphviz.org/Gallery/undirected/gd_1994_2007.html
121 | * Graphviz and network maps (icons are a bit ugly tho): http://www.graphviz.org/Gallery/undirected/networkmap_twopi.html
122 | * For manual graphs (meh) - requires probably generating an output properly formatted like XML. Pain to maintain: https://community.spiceworks.com/topic/521280-i-need-software-that-make-my-whole-network-diagram-automatically
123 |
--------------------------------------------------------------------------------
/bookmarks.txt:
--------------------------------------------------------------------------------
1 | http://pygraphviz.github.io/documentation/pygraphviz-1.3rc1/reference/agraph.html
2 | https://networkx.readthedocs.io/en/stable/reference/introduction.html
3 | https://networkx.readthedocs.io/en/stable/tutorial/tutorial.html#nodes
4 | https://networkx.readthedocs.io/en/stable/reference/generated/networkx.relabel.convert_node_labels_to_integers.html?highlight=convert_node_labels_to_integers#networkx.relabel.convert_node_labels_to_integers
5 |
--------------------------------------------------------------------------------
/graphs.md:
--------------------------------------------------------------------------------
1 | Notes on graph making vs. data source
2 | -------------------------------------
3 |
4 | A few blurbs on what each source file can add to the global network graph.
5 |
6 | Terminology:
7 |
8 | * "centre node" is the node that collected information in the most recent run
9 |
10 | Supported inputs:
11 |
12 | * Arp cache
13 | * Routing table
14 | * Traceroute
15 | * Network adapter information (ifconfig, ipconfig, etc.)
16 |
17 | Each input augments the final graph in different ways. Ultimately the tool could present a prioritised list of nodes so that e.g. running a traceroute against the first node will provide the missing information needed to determine the exact number of hops between centre and target, and so on.
18 |
19 |
20 | ### ARP cache
21 |
22 | An arp cache would show only direct neighbours (and not all of them). The resulting graph would be a many-to-many dense graph with an unknown centre node, and a set of nodes directly connected to it.
23 |
24 | Assumptions:
25 |
26 | * Every node in the cache is a direct neighbour of all other nodes
27 |
28 |
29 | ### Routing table
30 |
31 | A routing table shows sources and sinks (borrowing from graph terminlogy), not necessarily directly connected.
32 |
33 | Routing entries are:
34 |
35 | * Nodes
36 | * Networks
37 |
38 | Also a routing table could provide the IP of the current node in some form or another. For example in a Windows `route print` command we can see:
39 |
40 | 0.0.0.0 0.0.0.0 10.137.2.1 10.137.2.16 10
41 | 10.137.2.0 255.255.255.0 On-link 10.137.2.16 266
42 | 10.137.2.16 255.255.255.255 On-link 10.137.2.16 266
43 | 10.137.2.255 255.255.255.255 On-link 10.137.2.16 266
44 |
45 | Where `10.137.2.16` is the address of the ethernet adaptor.
46 |
47 | Adding a node from a routing table augments the graph in two ways:
48 |
49 | * If it's in the same network, it's a direct edge
50 | * If it's in a different network, then:
51 | * The gateway is a direct edge from the centre node
52 | * The other network is a new graph to augment, linked to the default gateway by one or more hops
53 |
54 |
55 | ### Traceroute
56 |
57 | A traceroute fills in the gaps of a routing table by providing direct edges between hosts. Ideally the tool should suggest which hosts should be tracerouted (first).
58 |
59 |
60 | ### Network Adaptor information
61 |
62 | The various `ifconfig`, `ip addr`, `ipconfig` are useful only in linux to know the IP of the centre node.
63 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
18 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/networkmap/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lorenzog/NetworkMap/f5faf176664e12d33dc2ccd81a7e68fa4c91ab6d/networkmap/__init__.py
--------------------------------------------------------------------------------
/networkmap/__main__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 | """
3 | POC of a network grapher
4 | ========================
5 |
6 | This tool parses various network 'dumps' such as traceroute, arp tables etc.
7 | and produces a growing network graph of all reachable nodes.
8 |
9 | """
10 | import argparse
11 | import logging
12 | import json
13 | # import pprint
14 | import os
15 | import shutil
16 |
17 | import networkx as nx
18 |
19 | from errors import MyException
20 | from netgrapher import grow_graph
21 | from parsers import SUPPORTED_OS, SUPPORTED_DUMPFILES
22 | # from node import Node
23 |
24 | __author__ = "Lorenzo G. https://github.com/lorenzog"
25 |
26 |
27 | logger = logging.getLogger('netgrapher')
28 |
29 | DEFAULT_SAVEFILE = "networkmap"
30 | DEFAULT_GRAPHIMG = "/tmp/out.png"
31 |
32 | SUPPORTED_FILE_FORMATS = [
33 | 'GEXF',
34 | 'DOT',
35 | 'JSON',
36 | 'GRAPHML',
37 | ]
38 | DEFAULT_FILE_FORMAT = 'JSON'
39 |
40 |
41 | # see: http://stackoverflow.com/a/37578709/204634
42 | # but also: https://networkx.readthedocs.io/en/stable/reference/drawing.html#module-networkx.drawing.nx_agraph
43 | def load_graph(savefile, file_format):
44 | """Does what it says on the tin(c)"""
45 | if savefile is None:
46 | return nx.Graph()
47 | if os.path.exists(savefile):
48 | if file_format == 'GEXF':
49 | # importing here because if there's no xml.etree installed,
50 | # things should still work with other file formats.
51 | from xml.etree.cElementTree import ParseError as cParseError
52 | from xml.etree.ElementTree import ParseError as ParseError
53 |
54 | try:
55 | g = nx.read_gexf(savefile)
56 | # I hate catching 'Exception' but read_gexf raises
57 | # 'cElementTree.ParseError' (or ElementTree.ParseError, no 'c')
58 | # which is nowhere to be found
59 | # except Exception as e:
60 | # alternative solution, not sure it's better or not:
61 | except (cParseError, ParseError) as e:
62 | raise MyException("Cannot read file {} using format {}: {}".format(
63 | savefile, file_format, e))
64 | elif file_format == 'DOT':
65 | import pygraphviz
66 | try:
67 | g = nx.nx_agraph.read_dot(savefile)
68 | except ImportError:
69 | raise MyException("Cannot find pygraphviz")
70 | except pygraphviz.agraph.DotError as e:
71 | logger.error("Cannot load file {}".format(savefile))
72 | raise MyException(e)
73 | elif file_format == 'JSON':
74 | from networkx.readwrite import json_graph
75 | with open(savefile) as f:
76 | json_data = json.load(f)
77 | g = json_graph.node_link_graph(json_data)
78 | logger.debug("Loaded JSON savefile. Nodes: {}".format(
79 | g.nodes(data=True)))
80 | elif file_format == 'GRAPHML':
81 | from networkx.readwrite import graphml
82 | g = graphml.read_graphml(savefile)
83 | else:
84 | raise MyException("Unknown file format {}".format(file_format))
85 | else:
86 | logger.info("Savefile not found - initialising new graph...")
87 | g = nx.Graph()
88 | return g
89 |
90 |
91 | def save_graph(graph, savefile, file_format):
92 | """Does what it says on the tin(c)"""
93 | if os.path.exists(savefile):
94 | shutil.copy(savefile, "{}.bak".format(savefile))
95 | logger.info("Network DOT file backup saved: {}.bak".format(savefile))
96 |
97 | if file_format == 'GEXF':
98 | nx.write_gexf(graph, savefile)
99 | elif file_format == 'DOT':
100 | nx.nx_agraph.write_dot(graph, savefile)
101 | elif file_format == 'JSON':
102 | from networkx.readwrite import json_graph
103 | json_data = json_graph.node_link_data(graph)
104 | with open(savefile, 'w') as f:
105 | # f.write(json_data)
106 | json.dump(json_data, f, indent=4)
107 | elif file_format == 'GRAPHML':
108 | from networkx.readwrite import graphml
109 | graphml.write_graphml(graph, savefile)
110 | else:
111 | logger.error("Unknown file format requested")
112 |
113 | logger.info("Network file saved to {}".format(savefile))
114 |
115 |
116 | def main():
117 | p = argparse.ArgumentParser()
118 | p.add_argument('-d', '--debug', action='store_true')
119 |
120 | # TODO this could be a list, for multiple interfaces. That makes it fun to
121 | # implement unless we consider each interface to be a separate 'node', and
122 | # join them with a stronger edge.
123 | p.add_argument(
124 | '-i', '--ip',
125 | help=("The IP address where the dumpfile was taken. "
126 | "Default: tries to guess bsaed on the content of the file")
127 | )
128 |
129 | p.add_argument(
130 | '-s', '--savefile',
131 | help="Use this file to store information. Creates it if it does not exist.",
132 | default=DEFAULT_SAVEFILE
133 | )
134 | # savefile format
135 | p.add_argument(
136 | '-f', '--file-format', choices=SUPPORTED_FILE_FORMATS,
137 | default=DEFAULT_FILE_FORMAT)
138 | p.add_argument(
139 | '-N', '--ignore-savefile', action='store_true',
140 | help="Don't read the savefile")
141 |
142 | p.add_argument('-n', '--dry-run', action='store_true')
143 |
144 | # the dump file to load
145 | p.add_argument('dumpfile')
146 | # we'll try to guess, but can override
147 | p.add_argument(
148 | '-t', '--dumpfile-type',
149 | help="Dumpfile type; default: tries to guess based on file format.",
150 | choices=SUPPORTED_DUMPFILES)
151 | p.add_argument(
152 | '-o', '--dumpfile-os',
153 | help="Operating System; default: tries to guess.",
154 | choices=SUPPORTED_OS)
155 |
156 | # run a http server?
157 | p.add_argument(
158 | '-H', '--serve_http', action='store_true',
159 | help="Automatically run a minimal HTTP server locally to show the result")
160 | args = p.parse_args()
161 |
162 | if args.debug:
163 | logger.setLevel(logging.DEBUG)
164 | logger.debug("Debug logging enabled")
165 |
166 | savefile = "{}{}{}".format(args.savefile, os.path.extsep, args.file_format.lower())
167 |
168 | if not os.path.exists(args.dumpfile):
169 | raise SystemExit("File {} does not exist".format(args.dumpfile))
170 |
171 | #
172 | # Boilerplate ends
173 | ###
174 |
175 | try:
176 | if args.ignore_savefile:
177 | logger.debug("Ignoring savefile")
178 | _savefile = None
179 | else:
180 | logger.debug("About to load file {}".format(savefile))
181 | _savefile = savefile
182 | loaded_graph = load_graph(_savefile, args.file_format)
183 | logger.debug("Loaded graph:\nnodes\t{}\nedges\t{}".format(loaded_graph.nodes(), loaded_graph.edges()))
184 | final_graph = grow_graph(
185 | loaded_graph, args.dumpfile,
186 | dumpfile_os=args.dumpfile_os,
187 | dumpfile_type=args.dumpfile_type,
188 | ip=args.ip
189 | )
190 | if not args.dry_run:
191 | save_graph(final_graph, savefile, args.file_format)
192 | else:
193 | logger.info("Dry-run mode selected -not writing into savefile")
194 | except MyException as e:
195 | logger.error("{}".format(e))
196 | raise SystemExit
197 |
198 | # as a freebie, produce a graph with graphviz already if it's a dot file
199 | # and if graphviz is installed
200 | if args.file_format == 'DOT':
201 | try:
202 | import pygraphviz as pgv
203 | # convert to image
204 | f = pgv.AGraph(savefile)
205 | f.layout(prog='circo')
206 | f.draw(DEFAULT_GRAPHIMG)
207 | logger.info("Graph image saved in {}".format(DEFAULT_GRAPHIMG))
208 | except ImportError as e:
209 | logger.error("Cannot find pygraphviz.")
210 | except IOError as e:
211 | logger.error(
212 | "Something went wrong when drawing, but the dot file is "
213 | "still good. Try one of the graphviz programs manually "
214 | "(e.g. neato, circo)")
215 |
216 | logger.info("\nProcessing complete.\n")
217 | # pretend we're a http server
218 | if args.serve_http:
219 | import SimpleHTTPServer
220 | import SocketServer
221 |
222 | PORT = 8000
223 | Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
224 | # how about we don't use 0.0.0.0 and avoid serving the local directory
225 | # to the entire world, eh
226 | httpd = SocketServer.TCPServer(("127.0.0.1", PORT), Handler)
227 |
228 | logger.info("Point your browser at http://localhost:{}".format(PORT))
229 | try:
230 | httpd.serve_forever()
231 | except KeyboardInterrupt:
232 | logger.info("Shutting down web server...")
233 |
234 | else:
235 | logger.info(
236 | "To show the output in a web browser, use the '-H' switch or "
237 | "run \n\tpython -m SimpleHTTPServer\nand point your browser to "
238 | "http://localhost:8000/")
239 |
240 | exit(0)
241 |
242 |
243 | if __name__ == '__main__':
244 | main()
245 |
--------------------------------------------------------------------------------
/networkmap/errors.py:
--------------------------------------------------------------------------------
1 | class MyException(Exception):
2 | """Generic exception to handle program flow exits"""
3 | pass
4 |
--------------------------------------------------------------------------------
/networkmap/netgrapher.py:
--------------------------------------------------------------------------------
1 | # TODO add nmap support for host type
2 | # TODO add 'hosts' file for ip -> name support
3 | # NOTE: what about 'ghost' IPs or multicast/broadcast?
4 | # TODO add support for multi-interface
5 | # TODO to supply IP of host, perhaps use an ipconfig/ifconfig file? (useful for route parsing)
6 |
7 | import logging
8 |
9 | import networkx as nx
10 |
11 | import parsers
12 | from errors import MyException
13 |
14 |
15 | logger = logging.getLogger('netgrapher')
16 | logger.addHandler(logging.StreamHandler())
17 | logger.setLevel(logging.INFO)
18 |
19 |
20 | def extract_from_arp(dumpfile, dumpfile_os, ip):
21 | """Given an arp dump, extracts IPs and adds them as nodes to the graph"""
22 | if dumpfile_os == 'windows':
23 | # windows arp contains local ip
24 | centre_node, neighbours = parsers.parse_windows_arp(dumpfile, ip)
25 | # so we can verify it matches the supplied IP (if any)
26 | if ip is not None and centre_node != ip:
27 | raise MyException(
28 | "The IP found in the ARP file is {} but "
29 | "you supplied {}. Aborting...".format(
30 | centre_node, ip)
31 | )
32 | elif dumpfile_os == 'linux':
33 | if ip is None:
34 | raise MyException(
35 | "Linux ARP does not contain the IP of the "
36 | "centre node; please supply it manually\n")
37 | centre_node = ip
38 | neighbours = parsers.parse_linux_arp(dumpfile)
39 | else:
40 | raise NotImplementedError("Sorry, haven't written this yet")
41 |
42 | g = nx.Graph()
43 | for node in neighbours:
44 | _node_ip, _node_mac = node
45 | g.add_node(_node_ip, ip_addr=_node_ip, mac=_node_mac)
46 | g.add_edge(centre_node, _node_ip, link_type="arp")
47 |
48 | logger.debug("Local graph:\nnodes\t{}\nedges\t{}".format(g.nodes(data=True), g.edges(data=True)))
49 | return g
50 |
51 |
52 | def extract_from_route(dumpfile, dumpfile_os, ip):
53 | if dumpfile_os == 'linux':
54 | if ip is None:
55 | raise MyException(
56 | "Linux routing output does not contain the IP of the "
57 | "centre node; please supply it manually\n")
58 | # host and network routes have the form: (destination, netmask, gateway)
59 | # default routes is an IP
60 | host_routes, network_routes, default_route = parsers.parse_linux_route(dumpfile)
61 | else:
62 | # TODO
63 | raise NotImplementedError("Sorry, haven't written this yet")
64 |
65 | g = nx.Graph()
66 | # add current
67 | g.add_node(ip, ip_addr=ip, node_type="centre_node")
68 |
69 | for dr in default_route:
70 | # add the default route as direct neighbour to the graph, with
71 | # an edge leading to a 'default' network/internet.
72 | g.add_node(dr, ip_addr=dr, node_type="default_gateway")
73 | g.add_edge(ip, dr, link_type="default_route")
74 |
75 | for nr in network_routes:
76 | _network, _mask, _gw = nr
77 | # Then add all network routes as edges to other networks
78 | g.add_node(_network, netmask=_mask, node_type="network")
79 | if _gw != '0.0.0.0':
80 | # using the gateway if present;
81 | g.add_node(_gw, node_type="network_gateway")
82 | g.add_edge(ip, _gw, link_type="network_route")
83 | # XXX this could be a link through several networks
84 | g.add_edge(_gw, _network, link_type="network_link")
85 | else:
86 | # or simply as a network route
87 | g.add_edge(ip, _network, link_type="network_route")
88 |
89 | for node in host_routes:
90 | # TODO
91 | # Lastly, add all host routes as edges *through* either a network route or
92 | # a default route. Not sure whether I'll have to parse IPs to understand this.
93 | # perhaps using the ipaddr library?
94 | pass
95 |
96 | return g
97 |
98 |
99 | def extract_from_tr(dumpfile, dumpfile_os, ip):
100 | # NOTE
101 | # here each hop can be a new node, with an edge connecting back towards `ip`
102 | if dumpfile_os == 'linux':
103 | # returns an (ordered!) list of nodes, where the first is the centre node
104 | hops = parsers.parse_linux_tr(dumpfile, ip)
105 | else:
106 | # TODO windows traceroute
107 | raise NotImplementedError("Sorry, haven't written this yet")
108 |
109 | g = nx.Graph()
110 | if len(hops) == 0:
111 | logger.info("No hops found in traceroute file")
112 | return g
113 |
114 | # link each node with the preceding one
115 | for hopno, node in enumerate(hops[1:]):
116 | g.add_edge(hops[hopno], node, link_type="traceroute")
117 |
118 | return g
119 |
120 |
121 | def grow_graph(loaded_graph, dumpfile, dumpfile_os=None, dumpfile_type=None, ip=None):
122 | """Given a bunch of nodes, if they are not dupes add to graph"""
123 |
124 | if dumpfile_type is None or dumpfile_os is None:
125 | # have to open the file for reading once anyway
126 | guessed_type, guessed_os = parsers.guess_dumpfile_type_and_os(dumpfile)
127 | logger.info("Guessed file type: {}, OS: {}".format(guessed_type, guessed_os))
128 |
129 | # decide whether to use the guess or the specified dumpfile type
130 | if dumpfile_type is None:
131 | if guessed_type is None:
132 | raise MyException("Cannot guess file type. Please specify it manually.")
133 | else:
134 | dumpfile_type = guessed_type
135 | else:
136 | if guessed_type is not None and dumpfile_type != guessed_type:
137 | logger.warn("Guessed type does not match specified type. Ignoring guess.")
138 |
139 | # same for the OS
140 | if dumpfile_os is None:
141 | if guessed_os is None:
142 | raise MyException("Cannot guess OS. Please specify it manually.")
143 | else:
144 | dumpfile_os = guessed_os
145 | else:
146 | if guessed_os is not None and dumpfile_os != guessed_os:
147 | logger.warn("Guessed type does not match specified type. Ignoring guess.")
148 |
149 | logger.debug("Dumpfile: {}, OS: {}".format(dumpfile_type, dumpfile_os))
150 |
151 | if dumpfile_type == 'arp':
152 | new_graph = extract_from_arp(dumpfile, dumpfile_os, ip)
153 | elif dumpfile_type == 'route':
154 | new_graph = extract_from_route(dumpfile, dumpfile_os, ip)
155 | elif dumpfile_type == 'traceroute':
156 | new_graph = extract_from_tr(dumpfile, dumpfile_os, ip)
157 | else:
158 | # this bubbles to the user for now
159 | raise NotImplementedError("This dumpfile is not supported.")
160 |
161 | ###
162 | # XXX
163 | # how about:
164 | # join the two graphs as independent networks
165 | # but make the centre the same node (?)
166 |
167 | # NOTE:
168 | # 1. arp tables give immediate neighbours so can add an edge.
169 | # 2. routes can give hosts that are not immediately adjacent. In this case,
170 | # they should not be added as direct edges when growing the graph.
171 | # 3. traceroutes show paths (i.e. direct edges)
172 | logger.debug("Loaded graph nodes {}\nedges {}".format(loaded_graph.nodes(data=True), loaded_graph.edges(data=True)))
173 | logger.debug("New graph nodes {}\nedges {}".format(new_graph.nodes(data=True), new_graph.edges(data=True)))
174 | # final_graph = nx.disjoint_union(loaded_graph, new_graph)
175 | # final_graph = nx.union(loaded_graph, new_graph)
176 | # thanks, stack overflow
177 | # http://stackoverflow.com/a/32697415/204634
178 | final_graph = nx.compose(loaded_graph, new_graph)
179 | return final_graph
180 |
--------------------------------------------------------------------------------
/networkmap/parsers.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import re
3 |
4 | # from node import Node
5 | from errors import MyException
6 |
7 |
8 | # XXX this has to be the same name as the logger object in
9 | # netgrapher.py...
10 | logger = logging.getLogger('netgrapher')
11 |
12 | # NOTE there can be more than one way of matching; the regexps are applied to
13 | # all lines of the file until a match is found
14 | guess_data = (
15 | (('arp', 'windows'), r'^Interface:\s+'),
16 | (('arp', 'linux'), r'^Address\s+HWtype\s+HWaddress\s+Flags\s+Mask\s+Iface$'),
17 | (('arp', 'openbsd'), r'^Host\s+Ethernet\sAddress\s+Netif\sExpire\sFlags$'),
18 | #
19 | (('traceroute', 'linux'), r'^traceroute to .+ \([\d.]+\), \d+ hops max, \d+ byte packets$'),
20 | # doubled, just because
21 | (('route', 'linux'), r'^Kernel IP routing table$'),
22 | (('route', 'linux'), r'^Destination\s+Gateway\s+Genmask\s+Flags\sMetric\sRef\s+Use\sIface$'),
23 | (('route', 'windows'), r'===========================================================================')
24 | )
25 |
26 | # build separate lists for the help menu
27 | SUPPORTED_DUMPFILES = set(a[0] for a, b in guess_data)
28 | SUPPORTED_OS = set(a[1] for a, b in guess_data)
29 |
30 |
31 | # XXX perhaps this could be extended by using more than one regexp to match
32 | # across lines? Maybe using a defaultDict with a list of regexps instead of tuples
33 | def guess_dumpfile_type_and_os(dumpfile):
34 | """Returns file_type, os when any line of the input file matches the regexp"""
35 | with open(dumpfile) as f:
36 | # read every line exactly once
37 | for line in f.readlines():
38 | logger.debug("line:\n{}".format(line))
39 | # ...and try to match it against a known os/type tuple
40 | for type_os, regexp in guess_data:
41 | m = re.match(regexp, line)
42 | if m:
43 | # got match
44 | file_type, os = type_os
45 | logger.debug("Match: {}, {}".format(file_type, os))
46 | return file_type, os
47 | logger.debug("No match for {}".format(type_os))
48 |
49 | return None, None
50 |
51 |
52 | def parse_linux_tr(dumpfile, ip):
53 | hops = []
54 | if ip is None:
55 | raise MyException("Linux ARP does not contain the IP of the "
56 | "centre node; please supply it manually with --ip\n")
57 | hops.append(ip)
58 | with open(dumpfile) as f:
59 | for line in f.readlines():
60 | # 1 10.137.4.1 0.550 ms 0.463 ms 0.383 ms
61 | m = re.match(r'\s+\d+\s+([\w.]+)', line)
62 | if m and len(m.groups()) >= 1:
63 | _hop_ip = m.group(1)
64 | logger.debug("Found hop: {}".format(_hop_ip))
65 | hops.append(_hop_ip)
66 | return hops
67 |
68 |
69 | def parse_linux_arp(dumpfile):
70 | nodes = []
71 | with open(dumpfile) as f:
72 | for line in f.readlines():
73 | # Address HWtype HWaddress Flags Mask Iface
74 | # 10.137.1.8 ether 00:16:3e:5e:6c:06 C vif2.0
75 | # similar regexp than the windows arp, except it uses : instead of -
76 | m = re.match(r'([\w.]+)\s+\w+\s+(([0-9a-f]{2}:){5}[0-9a-f]{2})', line)
77 | if m and len(m.groups()) >= 2:
78 | _node_ip = m.group(1)
79 | _node_mac = m.group(2)
80 | logger.debug("Found node {} with mac {}".format(_node_ip, _node_mac))
81 | nodes.append((_node_ip, _node_mac))
82 | continue
83 | return nodes
84 |
85 |
86 | def parse_windows_arp(dumpfile, ip):
87 | """Windows ARP file parsing"""
88 | nodes = []
89 | with open(dumpfile) as f:
90 | for line in f.readlines():
91 | # the first line looks like:
92 | # Interface: 10.137.2.16 --- 0x11
93 | m = re.match(r'Interface: (.+) ---', line)
94 | if m and len(m.groups()) >= 1:
95 | _local_ip = m.group(1)
96 | logger.debug("Found centre node: {}".format(_local_ip))
97 | continue
98 |
99 | # lines with IPs and MAC addresses look like:
100 | # 10.137.2.1 fe-ff-ff-ff-ff-ff dynamic
101 | # regexp to match an IP: ([\w.]+)
102 | # regexp to match a mac: (([0-9a-f]{2}-){5}[0-9a-f])
103 | # start with two empty spaces,
104 | m = re.match(r' ([\w.]+)\s+(([0-9a-f]{2}-){5}[0-9a-f]{2})', line)
105 | if m and len(m.groups()) >= 2:
106 | _node_ip = m.group(1)
107 | _node_mac = m.group(2)
108 | logger.debug("Found node {} with mac {}".format(_node_ip, _node_mac))
109 | nodes.append((_node_ip, _node_mac))
110 | continue
111 |
112 | # centre node and neighbours
113 | return _local_ip, nodes
114 |
115 |
116 | def parse_linux_route(dumpfile):
117 | # NOTE from 'route' man page:
118 | # Flags Possible flags include
119 | # U (route is up)
120 | # H (target is a host)
121 | # G (use gateway)
122 | # R (reinstate route for dynamic routing)
123 | # D (dynamically installed by daemon or redirect)
124 | # M (modified from routing daemon or redirect)
125 | # A (installed by addrconf)
126 | # C (cache entry)
127 | # ! (reject route)
128 | host_routes = []
129 | network_routes = []
130 | default_routes = []
131 |
132 | with open(dumpfile) as f:
133 | for line in f.readlines():
134 | # skip first line
135 | m = re.match(r'Kernel IP routing table', line)
136 | if m is not None:
137 | continue
138 | # skip second line
139 | m = re.match(r"Destination\s+Gateway\s+Genmask", line)
140 | if m is not None:
141 | continue
142 |
143 | # regexp to match an IP: ([\w.]+)
144 | # Destination Gateway Genmask Flags Metric Ref Use Iface
145 | # 0.0.0.0 10.137.4.1 0.0.0.0 UG 0 0 0 eth0
146 | m = re.match(r'(?P[\w.]+)\s+(?P[\w.]+)\s+(?P[\w.]+)\s+(?P[\w.]+)', line)
147 | if m is not None:
148 | _dest = m.group('dest')
149 | _gw = m.group('gw')
150 | _mask = m.group('mask')
151 | _flags = m.group('flags')
152 |
153 | if _flags[0] != 'U':
154 | logger.debug("Route {} is not up; skipping...".format(line))
155 |
156 | # basic example, I'm sure it breaks in the face of some complex scenario
157 | if _dest == '0.0.0.0':
158 | logger.debug("Adding default gateway: {}".format(_dest))
159 | default_routes.append(_gw)
160 | # next line baby
161 | continue
162 |
163 | if 'H' in _flags:
164 | # it's a host route
165 | _hr = (_dest, _mask, _gw)
166 | logger.debug("Adding host route: {}".format(_hr))
167 | host_routes.append(_hr)
168 | continue
169 |
170 | # what's left must be a network route
171 | # TODO bar the odd cases like ! -- see notes on top of function
172 | _nr = (_dest, _mask, _gw)
173 | logger.debug("Adding network route: {}".format(_nr))
174 | network_routes.append(_nr)
175 |
176 | # host and network routes have the form: (destination, netmask, gateway)
177 | return host_routes, network_routes, default_routes
178 |
--------------------------------------------------------------------------------
/networkmap/test_parsers.py:
--------------------------------------------------------------------------------
1 | import os
2 | import logging
3 | import sys
4 |
5 |
6 | from parsers import guess_dumpfile_type_and_os as guess
7 |
8 | # hat tip: http://stackoverflow.com/a/7483862/204634
9 | logger = logging.getLogger('netgrapher')
10 | logger.addHandler(logging.StreamHandler(sys.stdout))
11 |
12 |
13 | SAMPLES_DIR = os.path.join(
14 | os.path.dirname(
15 | os.getcwd()),
16 | 'samples')
17 |
18 |
19 | arp_dir = os.path.join(SAMPLES_DIR, 'arp')
20 | tr_dir = os.path.join(SAMPLES_DIR, 'traceroute')
21 | route_dir = os.path.join(SAMPLES_DIR, 'route')
22 |
23 |
24 | class TestArp(object):
25 | def test_guess_linux(self):
26 | dumpfile = os.path.join(arp_dir, 'linux_arp.txt')
27 | _t, _o = guess(dumpfile)
28 | assert _t == 'arp'
29 | assert _o == 'linux'
30 |
31 | def test_guess_windows(self):
32 | dumpfile = os.path.join(arp_dir, 'windows_7_arp.txt')
33 | _t, _o = guess(dumpfile)
34 | assert _t == 'arp'
35 | assert _o == 'windows'
36 |
37 | def test_guess_obsd(self):
38 | dumpfile = os.path.join(arp_dir, 'openbsd_arp.txt')
39 | _t, _o = guess(dumpfile)
40 | assert _t == 'arp'
41 | assert _o == 'openbsd'
42 |
43 |
44 | class TestTraceroute(object):
45 | def test_guess_linux(self):
46 | dumpfile = os.path.join(tr_dir, 'linux_traceroute.txt')
47 | _t, _o = guess(dumpfile)
48 | assert _t == 'traceroute'
49 | assert _o == 'linux'
50 |
51 |
52 | class TestRoute(object):
53 | def test_guess_linux(self):
54 | dumpfile = os.path.join(route_dir, 'linux_route.txt')
55 | _t, _o = guess(dumpfile)
56 | assert _t == 'route'
57 | assert _o == 'linux'
58 |
59 | def test_guess_windows(self):
60 | dumpfile = os.path.join(route_dir, 'windows_7_route_print.txt')
61 | _t, _o = guess(dumpfile)
62 | assert _t == 'route'
63 | assert _o == 'windows'
64 |
--------------------------------------------------------------------------------
/notes.md:
--------------------------------------------------------------------------------
1 | Random notes
2 | ============
3 |
4 | installing pygraphviz on openbsd requires doing a 'export
5 | CPATH=:/usr/local/include' first.
6 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | decorator
2 | networkx
3 | pydotplus
4 | # pygraphviz
5 | pyparsing
6 | nose
7 | ipaddress
8 |
--------------------------------------------------------------------------------
/samples/arp/linux_arp.txt:
--------------------------------------------------------------------------------
1 | $ sudo arp -n
2 | Address HWtype HWaddress Flags Mask Iface
3 | 10.137.1.8 ether 00:16:3e:5e:6c:06 C vif2.0
4 | 192.168.1.1 ether b0:48:7a:de:46:64 C wlp0s1
5 |
6 |
--------------------------------------------------------------------------------
/samples/arp/openbsd_arp.txt:
--------------------------------------------------------------------------------
1 | # note - IP is 192.168.1.108
2 | $ arp -an
3 | Host Ethernet Address Netif Expire Flags
4 | 192.168.1.1 b0:48:7a:de:46:64 iwn0 19m57s
5 | 192.168.1.100 8c:2d:aa:58:e3:09 iwn0 19m57s
6 | 192.168.1.108 00:21:6b:c6:27:2e iwn0 permanent l
7 |
8 |
--------------------------------------------------------------------------------
/samples/arp/windows_7_arp.txt:
--------------------------------------------------------------------------------
1 |
2 | Interface: 10.137.2.16 --- 0x11
3 | Internet Address Physical Address Type
4 | 10.137.2.1 fe-ff-ff-ff-ff-ff dynamic
5 | 10.137.2.255 ff-ff-ff-ff-ff-ff static
6 | 224.0.0.22 01-00-5e-00-00-16 static
7 | 224.0.0.252 01-00-5e-00-00-fc static
8 | 239.255.255.250 01-00-5e-7f-ff-fa static
9 |
--------------------------------------------------------------------------------
/samples/arp/windows_7_arp2.txt:
--------------------------------------------------------------------------------
1 |
2 | Interface: 10.137.2.16 --- 0x11
3 | Internet Address Physical Address Type
4 | 10.137.2.2 fe-ff-ff-ff-ff-ff dynamic
5 | 224.0.0.22 01-00-5e-00-00-16 static
6 | 224.0.0.252 01-00-5e-00-00-fc static
7 | 239.255.255.250 01-00-5e-7f-ff-fa static
8 |
--------------------------------------------------------------------------------
/samples/ifconfig/linux_ifconfig.txt:
--------------------------------------------------------------------------------
1 | eth0 Link encap:Ethernet HWaddr 00:16:3e:5e:6c:0f
2 | inet addr:10.137.4.17 Bcast:10.255.255.255 Mask:255.255.255.255
3 | inet6 addr: fe80::216:3eff:fe5e:6c0f/64 Scope:Link
4 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
5 | RX packets:61812 errors:0 dropped:0 overruns:0 frame:0
6 | TX packets:40134 errors:0 dropped:0 overruns:0 carrier:0
7 | collisions:0 txqueuelen:1000
8 | RX bytes:76688916 (73.1 MiB) TX bytes:2600801 (2.4 MiB)
9 |
10 | lo Link encap:Local Loopback
11 | inet addr:127.0.0.1 Mask:255.0.0.0
12 | inet6 addr: ::1/128 Scope:Host
13 | UP LOOPBACK RUNNING MTU:65536 Metric:1
14 | RX packets:25 errors:0 dropped:0 overruns:0 frame:0
15 | TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
16 | collisions:0 txqueuelen:0
17 | RX bytes:2742 (2.6 KiB) TX bytes:2742 (2.6 KiB)
18 |
19 |
--------------------------------------------------------------------------------
/samples/ifconfig/linux_ip_addr.txt:
--------------------------------------------------------------------------------
1 | 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default
2 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3 | inet 127.0.0.1/8 scope host lo
4 | valid_lft forever preferred_lft forever
5 | inet6 ::1/128 scope host
6 | valid_lft forever preferred_lft forever
7 | 2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
8 | link/ether 00:16:3e:5e:6c:0f brd ff:ff:ff:ff:ff:ff
9 | inet 10.137.4.17/32 brd 10.255.255.255 scope global eth0
10 | valid_lft forever preferred_lft forever
11 | inet6 fe80::216:3eff:fe5e:6c0f/64 scope link
12 | valid_lft forever preferred_lft forever
13 |
--------------------------------------------------------------------------------
/samples/ipconfig/windows_7_ipconfig.txt:
--------------------------------------------------------------------------------
1 |
2 | Windows IP Configuration
3 |
4 | Host Name . . . . . . . . . . . . : lorenzos-vm-PC
5 | Primary Dns Suffix . . . . . . . :
6 | Node Type . . . . . . . . . . . . : Hybrid
7 | IP Routing Enabled. . . . . . . . : No
8 | WINS Proxy Enabled. . . . . . . . : No
9 |
10 | Ethernet adapter Local Area Connection 2:
11 |
12 | Connection-specific DNS Suffix . :
13 | Description . . . . . . . . . . . : Xen PV Network Device #0
14 | Physical Address. . . . . . . . . : 00-16-3E-5E-6C-0E
15 | DHCP Enabled. . . . . . . . . . . : Yes
16 | Autoconfiguration Enabled . . . . : Yes
17 | Link-local IPv6 Address . . . . . : fe80::c4b6:22d8:dea7:5028%17(Preferred)
18 | IPv4 Address. . . . . . . . . . . : 10.137.2.16(Preferred)
19 | Subnet Mask . . . . . . . . . . . : 255.255.255.0
20 | Default Gateway . . . . . . . . . : 10.137.2.1
21 | DNS Servers . . . . . . . . . . . : 10.137.2.1
22 | NetBIOS over Tcpip. . . . . . . . : Enabled
23 |
24 | Tunnel adapter Local Area Connection* 9:
25 |
26 | Media State . . . . . . . . . . . : Media disconnected
27 | Connection-specific DNS Suffix . :
28 | Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
29 | Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
30 | DHCP Enabled. . . . . . . . . . . : No
31 | Autoconfiguration Enabled . . . . : Yes
32 |
33 | Tunnel adapter isatap.{E405A5B4-FE74-4B7A-B7FA-5229B9F59C68}:
34 |
35 | Media State . . . . . . . . . . . : Media disconnected
36 | Connection-specific DNS Suffix . :
37 | Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
38 | Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
39 | DHCP Enabled. . . . . . . . . . . : No
40 | Autoconfiguration Enabled . . . . : Yes
41 |
--------------------------------------------------------------------------------
/samples/route/linux_ip_route.txt:
--------------------------------------------------------------------------------
1 | $ sudo ip route
2 | default via 10.137.4.1 dev eth0
3 | 10.137.4.1 dev eth0 scope link
4 |
--------------------------------------------------------------------------------
/samples/route/linux_netstat.txt:
--------------------------------------------------------------------------------
1 | $ sudo netstat -arn
2 | Kernel IP routing table
3 | Destination Gateway Genmask Flags MSS Window irtt Iface
4 | 0.0.0.0 10.137.4.1 0.0.0.0 UG 0 0 0 eth0
5 | 10.137.4.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
6 |
--------------------------------------------------------------------------------
/samples/route/linux_route.txt:
--------------------------------------------------------------------------------
1 | $ sudo route -n
2 | Kernel IP routing table
3 | Destination Gateway Genmask Flags Metric Ref Use Iface
4 | 0.0.0.0 10.137.4.1 0.0.0.0 UG 0 0 0 eth0
5 | 10.137.4.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
6 |
--------------------------------------------------------------------------------
/samples/route/windows_7_route_print.txt:
--------------------------------------------------------------------------------
1 | ===========================================================================
2 | Interface List
3 | 17...00 16 3e 5e 6c 0e ......Xen PV Network Device #0
4 | 1...........................Software Loopback Interface 1
5 | 12...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
6 | 15...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #4
7 | ===========================================================================
8 |
9 | IPv4 Route Table
10 | ===========================================================================
11 | Active Routes:
12 | Network Destination Netmask Gateway Interface Metric
13 | 0.0.0.0 0.0.0.0 10.137.2.1 10.137.2.16 10
14 | 10.137.2.0 255.255.255.0 On-link 10.137.2.16 266
15 | 10.137.2.16 255.255.255.255 On-link 10.137.2.16 266
16 | 10.137.2.255 255.255.255.255 On-link 10.137.2.16 266
17 | 127.0.0.0 255.0.0.0 On-link 127.0.0.1 306
18 | 127.0.0.1 255.255.255.255 On-link 127.0.0.1 306
19 | 127.255.255.255 255.255.255.255 On-link 127.0.0.1 306
20 | 224.0.0.0 240.0.0.0 On-link 127.0.0.1 306
21 | 224.0.0.0 240.0.0.0 On-link 10.137.2.16 266
22 | 255.255.255.255 255.255.255.255 On-link 127.0.0.1 306
23 | 255.255.255.255 255.255.255.255 On-link 10.137.2.16 266
24 | ===========================================================================
25 | Persistent Routes:
26 | Network Address Netmask Gateway Address Metric
27 | 0.0.0.0 0.0.0.0 10.137.2.1 Default
28 | ===========================================================================
29 |
30 | IPv6 Route Table
31 | ===========================================================================
32 | Active Routes:
33 | If Metric Network Destination Gateway
34 | 1 306 ::1/128 On-link
35 | 17 266 fe80::/64 On-link
36 | 17 266 fe80::c4b6:22d8:dea7:5028/128
37 | On-link
38 | 1 306 ff00::/8 On-link
39 | 17 266 ff00::/8 On-link
40 | ===========================================================================
41 | Persistent Routes:
42 | None
43 |
--------------------------------------------------------------------------------
/samples/traceroute/linux_traceroute.txt:
--------------------------------------------------------------------------------
1 | traceroute to www.google.com (216.58.209.36), 30 hops max, 60 byte packets
2 | 1 10.137.4.1 0.550 ms 0.463 ms 0.383 ms
3 | 2 10.137.2.1 1.615 ms 1.569 ms 1.573 ms
4 | 3 10.137.1.1 1.024 ms 0.882 ms 0.762 ms
5 | 4 192.168.100.1 4.143 ms 4.087 ms 4.043 ms
6 | 5 164.39.5.205 4.003 ms 6.655 ms 6.629 ms
7 | 6 164.39.17.57 6.594 ms 6.228 ms 8.568 ms
8 | 7 77.75.190.137 8.295 ms 7.997 ms 7.912 ms
9 | 8 85.199.239.161 10.893 ms 13.227 ms 13.160 ms
10 | 9 85.199.239.133 10.583 ms 10.473 ms 10.396 ms
11 | 10 51.179.161.118 13.176 ms 13.090 ms 10.822 ms
12 | 11 212.187.136.77 10.747 ms 13.587 ms 13.524 ms
13 | 12 4.69.166.9 14.991 ms 4.69.166.1 14.980 ms 14.915 ms
14 | 13 72.14.203.126 17.535 ms 14.877 ms 17.954 ms
15 | 14 209.85.241.145 15.724 ms 72.14.234.98 15.510 ms 209.85.255.78 15.474 ms
16 | 15 66.249.94.216 29.740 ms 209.85.143.67 12.530 ms 66.249.94.216 26.740 ms
17 | 16 216.239.48.238 26.592 ms 26.556 ms 209.85.249.22 28.131 ms
18 | 17 216.239.54.197 23.717 ms 209.85.143.29 24.494 ms 216.239.54.197 24.179 ms
19 | 18 66.249.95.38 33.383 ms 108.170.232.76 30.879 ms 30.789 ms
20 | 19 216.239.58.5 42.111 ms 42.055 ms 216.239.57.241 87.726 ms
21 | 20 72.14.236.79 97.776 ms 97.702 ms 83.873 ms
22 | 21 216.58.209.36 83.633 ms 83.529 ms 83.297 ms
23 |
--------------------------------------------------------------------------------
/simplenetwork.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lorenzog/NetworkMap/f5faf176664e12d33dc2ccd81a7e68fa4c91ab6d/simplenetwork.png
--------------------------------------------------------------------------------