← pynet

exercise 2

9eba0d800401d81534c57aadae920373a89d9a4b · ovidiucs · Sep 17, 2015 23:24

+19 −5 · 3 files changed

  • course_2/ex2_binary_convert.d +16 −0
  • course_2/ex2_binary_convert.py +1 −2
  • course_2/ex3_as_path.py +2 −3
diff --git a/course_2/ex2_binary_convert.d b/course_2/ex2_binary_convert.d
new file mode 100644
index 0000000..1b5298f
--- /dev/null
+++ b/course_2/ex2_binary_convert.d
@@ -0,0 +1,16 @@
+import std.stdio;
+import std.string;
+import std.conv;
+import std.format;
+
+void main()
+{
+   write(" > ");
+   string ip_address = chomp(readln);
+   string[] arr = split(ip_address,'.');
+   writefln("%20s %20s %20s %20s", "first octet", "second octet", "third octet",
+         "fourth octet");
+   foreach(i; arr[]){
+      writef("%20.08b",to!int(i)); 
+   }write('\n');
+}
diff --git a/course_2/ex2_binary_convert.py b/course_2/ex2_binary_convert.py
index e97f025..18d447a 100644
--- a/course_2/ex2_binary_convert.py
+++ b/course_2/ex2_binary_convert.py
@@ -1,4 +1,3 @@
-
 print "Input the network"
 octets = raw_input('> ')
 s      = octets.split('.')
@@ -10,6 +9,6 @@ fourth_octet  = int(s[3])
 
 print "%0s %20s %20s %20s" % \
               ("first_octet", "second_octet", "third_octet", "fourth_octet")
-              print "%0s %20s %20s %20s" % \
+print "%0s %20s %20s %20s" % \
               ('{0:08b}'.format(first_octet),'{0:08b}'.format(second_octet),
                '{0:08b}'.format(third_octet),'{0:08b}'.format(fourth_octet))
diff --git a/course_2/ex3_as_path.py b/course_2/ex3_as_path.py
index 5777d21..e40ec55 100644
--- a/course_2/ex3_as_path.py
+++ b/course_2/ex3_as_path.py
@@ -1,10 +1,9 @@
 entry1 = "*  1.0.192.0/18   157.130.10.233        0 701 38040 9737 i"
 entry2 = "*  1.1.1.0/24       157.130.10.233        0 701 1299 15169 i"
 entry3 = "*  1.1.42.0/24     157.130.10.233        0 701 9505 17408 2.1465 i"
-entry4 = "*  1.0.192.0/19   157.130.10.233        0 701 6762 6762 6762 6762
-38040 9737 i"
+entry4 = "*  1.0.192.0/19   157.130.10.233        0 701 6762 6762 6762 6762 38040 9737 i"
 
 print "%15s %15s" % ("ip_prefix", "as_path")
 
 for entry in entry1,entry2, entry3, entry4:
-        print "%15s %15s" % (entry.split()[1], entry.s
+    print "%15s %15s" % (entry.split()[1], entry.split()[4:-1])