Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 6th, 2003, 05:01 PM
carnt carnt is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 carnt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy pYTHON with http ???????

I dont know anything about python ,so i begin to read manuals etc from various locations.
But i have a basic question here, please if someone know help
Thanks .

Look at this :

<a href=\"file://", lease, "\">
The "lease" is just a variable that receive a IP address that my python read from a file.
But when i see in the page appear with a space like this
file:// ipaddress
-------|---------
This space can't exist !!!!

How can I avoid this little space problem ? It's just a simple program to read my dhcpd.leases and take the IP'S and Name's of people connected then show into a page.
When the person click on the IP then the browser open the shared resources .
Vary simple, but i don't know how avoid this

Thanks alot !!!

Carlos.

Here is the complete file .
----------------------------------

#!/usr/bin/python
import string, os
from sys import stdout

#-------
#LeaseFile = "/etc/dhcpd.leases" # if you have Redhat before 6.1
LeaseFile = "/var/lib/dhcp/dhcpd.leases" # if you have Redhat 6.1 or later

#------- Markers
# Entries in the /etc/dhcpd.leases file start with the word 'lease',
# may span several lines, and then end with a '}'. Lines that start
# with a TAB (\t) descibe the lease, i.e. mac address, start, etc.
newleaseMarker = 'l' # lease starts with 'l'
endleaseMarker = '}' # ends with a '}'
infoMarker = '\t' # lease informational lines start with a TAB
startsMarker = '\ts' # \tstarts
endMarker = '\te' # \tend
abandonedMarker = '\ta' # \tabandoned
clientMarker = '\tc' # \tclient
uidMarker = '\tu' # \tuid
hardwareMarker = '\th' # \thardware

# ------- Date arrays (pretty print the date)
weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
nthday = ["", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th",
"14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th
", "28th", "29th", "30th", "31st"]

#------- HTML Setup
print "Content-Type: text/html\n\n" # CGI header
print "<HTML><HEAD><LINK REL=\"stylesheet\" HREF=\"/lanlord/lanlord.css\">"

#------- Start the real work
indate = os.popen('date +"%A %B %m %r %Y"', 'r') # Get todays date
datedata = string.split(indate.readline())
today = string.atoi(datedata[2]) -1
print "</HEAD><BODY BGCOLOR=\"#ffffff\">"
print "<h3>DHCP Lease Report for", datedata[0], datedata[1], nthday[(today)], datedata[3], datedata[5], dated
ata[4], "</h3>"
input = open(LeaseFile, 'r') # Open the leases file

L = { } # Initialize hash

for line in input.readlines():
if line[:1] != newleaseMarker:
if line[:1] != endleaseMarker:
if line[:2] == startsMarker:
sDayLeased = line[8:9]
sDateLeased= line[10:20]
sHourLeased = line[21:len(line) -2]
elif line[:2] == endMarker:
eDayLeased = line[6:7]
eDateLeased= line[8:18]
eHourLeased = line[19:len(line) -2]
elif line[:2] == abandonedMarker:
macLeased = "<em>Abandoned</em>"
elif line[:2] == clientMarker:
clientLeased = "<b>" +line[18:len(line) -3] + "</b>"
elif line[:2] == uidMarker:
pass # get any MAC address
off hardware line
elif line[:2] == hardwareMarker:
macLeased = line[19:len(line) -2]
else:
## print "**UNKOWN**", # Not one of the 'usual suspe
cts'
pass
else:
sd = string.atoi(sDayLeased)
ed = string.atoi(eDayLeased)
entry = macLeased + "*" + clientLeased + "*" + weekday[sd] + "*" + sDateLeased + "*"
+ sHourLeased + "*" + weekday[ed] + "*" + eDateLeased + "*" + eHourLeased
L[ipLeased] = {`ipLeased` : `entry`}

else:
ipLeased = line[6:len(line) -3]
clientLeased = 'None'
macLeased = 'None'

print "<h5>", len(L), " leases</h5><Table border=\"1\"><th>IP Address</th><th>Hostname</th><th>Lease Start</t
h><th>Lease End</th><th>MAC Address</th>"
dhcpLease = L.keys()
dhcpLease.sort()
for lease in dhcpLease:
infoLease = L[lease]
dataLease = infoLease.values()
infoLease = dataLease
lLease = string.splitfields(`infoLease`,"*")
lMac = lLease[0][3:21]
lDate = lLease[7][0:8]
print "<TR><td>", lease, "</td><td>", lLease[1],"</td><td>", lLease[2], lLease[4], lLease[3], "</td><
td>", lLease[5], lDate, lLease[6], "</td><td>",lMac,"</td></tr>\n"

print "</table><p><a href=\"file://", ipLeased, "\">Test Part</a></p></body></html>"

- End file

Just rename it into the cgi-bin with name test.cgi to see it working.
Can someone help here !!!
Thanks again .

Reply With Quote
  #2  
Old June 6th, 2003, 05:19 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Talking +

Hi carnt, the problem is that when you join a string with a , then the space btween that and the variable counts i.e.

print "hey", variable, "."

if you replace the , with a + then the spacd shouldnt be a problem.

Hope this is what you were looking for.

Take care,
Mark.

Reply With Quote
  #3  
Old June 6th, 2003, 06:45 PM
carnt carnt is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 carnt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's right !!! It's work !

Yep !
Thanks alot !!!!!!!!!!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > pYTHON with http ???????

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap