← pynet

exercise1

bdcda6bd3a1d35416ed7dab25c066449c4923c2e · ovidiucs · Sep 13, 2015 11:09

+11 · 1 file changed

  • course_2/ex1_input_network.py +11 −0
diff --git a/course_2/ex1_input_network.py b/course_2/ex1_input_network.py
new file mode 100644
index 0000000..e3753fc
--- /dev/null
+++ b/course_2/ex1_input_network.py
@@ -0,0 +1,11 @@
+print "Input address"
+octets = raw_input('> ')
+s = octets.split('.')
+
+if len(s) == 3:
+    s.append('0')
+elif len(s) == 4:
+    s[3] = '0'
+
+print "NETWORK NUMBER \t FIRST_OCTET_BINARY \t FIRST_OCTET_HEX"
+print "%0s %15s %15s" % ('.'.join(s), bin(int((s[0]))), hex(int((s[0]))))