Code.GeekInterview.com
  I am new, Sign me up!
 
Code Samples Python
 

ASCII value for IP address


Code ResourceAuthor: josephdinesh  

Difficulty Level:

Published: 8th Oct 2007   Read: 1713 times  

Filed in: Python
Add Comment


 


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

 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Comment


Members Please Login

Name:  Email: (Optional. Used for Notification)

Title:
 
Comment:
Validation Code: <=>  (Enter this code in text box)





Popular Coders

# Coder NameHits
1. josephdinesh1714

Active Coders

# Coder NameCodes
1. josephdinesh1

Refined Tags

 

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape