← pynet

exercises

328d86d91aa02af69d9dbc0a1bba2e4623fe5c33 · ovidiucs · Sep 9, 2015 12:11

+29 · 2 files changed

  • course_1/exercise_1.py +15 −0
  • course_1/exercise_3.py +14 −0
diff --git a/course_1/exercise_1.py b/course_1/exercise_1.py
new file mode 100644
index 0000000..1c1646a
--- /dev/null
+++ b/course_1/exercise_1.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python2
+'''
+1. Use the split method to divide the following IPv6 address into groups of 4
+hex digits (i.e. split on the ":")
+
+FE80:0000:0000:0000:0101:A3EF:EE1E:1719
+'''
+
+ipv6_address = 'FE80:0000:0000:0000:0101:A3EF:EE1E:1719'
+ipv6_address_section = ipv6_address.split(":")
+
+print '\n' +'IPv6 sections below'+ '\n'
+print ipv6_address_section,'\n'  
+
+print "Joined" +'\n\n'+  ":".join(ipv6_address_section) 
diff --git a/course_1/exercise_3.py b/course_1/exercise_3.py
new file mode 100755
index 0000000..8a977a8
--- /dev/null
+++ b/course_1/exercise_3.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python2
+
+'''
+Here is an example using this script where I echo an IP address into it and then
+the IP address is split into its octets.
+
+$ echo '192.168.1.1'  | ./test3.py 
+['192', '168', '1', '1\n']
+'''
+
+import fileinput
+
+for line in fileinput.input():
+        print line.rstrip().split('.')