git clone https://@opensourceprojects.eu/git/p/timbus/context-population/extractors/local/network-info-perl timbus-context-population-extractors-local-network-info-perl



File Date Author Commit
NetExtractor 2014-02-24 Nuno Martins Nuno Martins [2b1317] Commented bridge and firewall keys. This can be...
Readme.md 2014-02-24 Nuno Martins Nuno Martins [6ea7af] Merge branch 'feature_readme' into develop
network_extractor.pl 2014-02-19 Nuno Martins Nuno Martins [066733] Merge remote-tracking branch 'opensourceproject...

Read Me

Network Information

Network Information Extractor is a Perl script that extracts relevant configuration information and creates a JSON report file with that information.
This tool is useful to easily gather information that is disperse through virtual filesystems, and create a concise file with the relevant information. Moreover, it is also very useful to have all information gathered in one single file to restore all network configurations of a machine.

 

How to get the code

git clone https://opensourceprojects.eu/git/p/timbus/context-population/extractors/local/network-info-perl network-info

 

Requirements

  1. JSON Perl Distribution
  2. Moose Perl Distribution
  3. ifconfig tool

 

Install Requirements

1
2
cpanp install Moose
cpanp JSON

 

Collected Information

Network Information tool collects information about interfaces, route and nameservers.
Interfaces' information, except IPv4 and IPv6, is obtained from the sys virtual file system at /sys/class/net/ folder. Each subfolder has the interface name its related files. Each file has the relevant data, such as: address (with mac address), mtu, speed, etc. Regarding the IPv4 and IPv6, it was gathered through ifconfig command.
In Linux the nameservers information is available in the file /etc/resolv.conf, therefore the nameserver key in the json is the content of that file.
As Interfaces' information is present in the sys file system, the routing information is present in the proc file system. The /proc/net/route file holds the Kernel information related to routing. The routes key in the json reflects the information present in that file.

 

Altough the information, present in the json, is sufficient to have an accurate network view, we believe that a more thorough would have the bridges and firewall rules.

 

How to execute

1
perl network-extractor.pl

 

Network information format

format => id : "b744635a-9d6b-11e3-8ec0-da765d6aa4db",
result => data => routes[]
                  => interfaces[]
                  => nameservers[]
          => uuid: ""

 

Expected output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
   "format" : {
      "id" : "b744635a-9d6b-11e3-8ec0-da765d6aa4db"
   },
   "result" : {
      "data" : {
         "routes" : [
            {
               "flags" : "0003",
               "window" : "0",
               "destination" : "0.0.0.0",
               "gateway" : "##.##.##.###",
               "metric" : "0",
               "irtt" : "0",
               "use" : "0",
               "interface" : "eth0",
               "refcnt" : "0",
               "mask" : "0.0.0.0",
               "mtu" : "0"
            },
            {
               "flags" : "0001",
               "window" : "0",
               "destination" : "##.##.##.#",
               "gateway" : "0.0.0.0",
               "metric" : "1",
               "irtt" : "0",
               "use" : "0",
               "interface" : "eth0",
               "refcnt" : "0",
               "mask" : "255.255.255.0",
               "mtu" : "0"
            }
         ],
         "firewall" : {},
         "network_interfaces" : [
            {
               "ipv6" : "fe80::f2de:####:####:####",
               "macaddress" : "##:##:##:##:##:##",
               "ipv4" : "##.##.##.##",
               "speed" : "100",
               "name" : "eth0",
               "mtu" : "1500"
            },
            {
               "ipv6" : "::1",
               "macaddress" : "00:00:00:00:00:00",
               "ipv4" : "127.0.0.1",
               "speed" : null,
               "name" : "lo",
               "mtu" : "65536"
            },
         ],
         "nameservers" : [
            {
               "search" : "caixamagica.pt",
               "nameserver" : "127.0.1.1"
            }
         ],
         "bridges" : {}
      },
      "uuid" : "ccd60780-9d6b-11e3-9cc6-b01e563f1341"
   }
}

 

Author

Nuno Martins nuno.martins@caixamagica.pt
 

License

Copyright (c) 2014, Caixa Magica Software Lda (CMS).
The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium.
TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work.
See the License for the specific language governing permissions and limitation under the License.