Code.GeekInterview.com
 
Code Samples Python
 

ASCII value for IP address


Code ResourceAuthor: josephdinesh  

Difficulty Level:

Published: 8th Oct 2007   Read: 4160 times  

Filed in: Python
Add Comment


 

 

Sponsored Links


 

 

This is a script to get the ASCII value of the corresponding IP Address. To run this script python2.4 or later version should be installed on your computer. 

Copy the code below and save the file as ip.py. 

Arguments to run this code is:  python ip.py

 


Sample Code
  1.  
  2. #Script to get the ASCII value for the corresponding IP address
  3. p=int(raw_input("Enter p:"))
  4. q=int(raw_input("Enter q:"))
  5. r=int(raw_input("Enter r:"))
  6. s=int(raw_input("Enter s:"))
  7. x=256*(256*(256*p+q)+r)+s
  8. if p > 255:
  9.         print "Invalid IP address"
  10. elif q > 255:
  11.         print "Invalid IP address"
  12. elif r > 255:
  13.         print "Invalid IP address"
  14. elif s > 255:
  15.         print "Invalid IP address"
  16. elif x > 4294967295:
  17.         print "Invalid IP address"
  18. else:
  19.         print "The corresponding ASCII value for" ,p,".",q,".",r,".",s, "is" ,x
  20.  
Copyright GeekInterview.com


Next: Python Script Strings Basic


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. josephdinesh4161
2. ramamoorthymsc2762

Active Coders

# Coder NameCodes
1. josephdinesh1
2. ramamoorthymsc1

Refined Tags