Current location: Hot Scripts Forums » Programming Languages » Other Languages » Python Code Review/Question


Python Code Review/Question

Reply
  #1 (permalink)  
Old 01-28-09, 01:31 PM
-[OnTarget]- -[OnTarget]- is offline
Newbie Coder
 
Join Date: Mar 2005
Location: Orlando, Florida
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Python Code Review/Question

I'm mainly a PHP programmer however I've been dabbling in Python and absolutely love how simple everything is. I wrote a email filter to catch certain mail in about 30 minutes and now I have this new script which logs me into my campus' BlueSocket WIFI automatically.... Basically I was just wondering are there any ways I could have cut this down a bit more (maybe how I dealt with the gateway handling?)

Code:
#!/usr/bin/python
import urllib2, urllib, socket
username = 'USERNAME'
password = 'PASWORD'
ip = socket.gethostbyname(socket.gethostname())
gateway = ip.split('.')
gateway[3]='1'
gatewayip = gateway[0:4]
gate_ip = ".".join(gatewayip)
gatesip = "http://",gate_ip,"/login.pl"
g = "".join(gatesip)
login = urllib.urlencode({'customlogin': 1, '_FORM_SUBMIT': 1, 'which_form': 'reg', 'destination': '', 'error': '', 'source': '128.186.232.83','SUBMIT': 'Log In', 'bs_name': username, 'bs_password': password});
e = urllib2.urlopen(g, login)
print "Tried...",g
print "Logged in!"
Thanks in advance.

PS: How come there isn't a Python forum
__________________
BlueScripts - Free PHP Scripts
Reply With Quote
  #2 (permalink)  
Old 02-06-09, 10:53 PM
Psybadek Psybadek is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Florida
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
Well I would say there isn't a Python forum because I dont know how many of the regulars know Python, plus there probably isn't a lot of Python topics to have one.
Reply With Quote
  #3 (permalink)  
Old 03-11-09, 03:00 AM
furthersorion furthersorion is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I think a python forum would be a good idea if there are indeed enough people interested.
Reply With Quote
  #4 (permalink)  
Old 03-17-09, 04:45 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Here's what you can do to "improve" (don't really know if it's any improvement at all) for the gateway defining:
Code:
#!/usr/bin/python
import urllib2, urllib, socket
username = 'USERNAME'
password = 'PASWORD'
ip = socket.gethostbyname(socket.gethostname())
ip = ip.rpartition ('.')[0]
login = urllib.urlencode({'customlogin': 1, '_FORM_SUBMIT': 1, 'which_form': 'reg', 'destination': '', 'error': '', 'source': '128.186.232.83','SUBMIT': 'Log In', 'bs_name': username, 'bs_password': password});
e = urllib2.urlopen("http://%s.1/login.pl" % ip, login)
print "Tried... http://%s.1/login.pl" % ip
print "Logged in!"
It saves you the splitting, and setting the last byte of the ip address (notice how I added the '1' within the url string itself).

We used to have a Python forum here, but there's was so little activity on it that we decided to close it down.
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
List of Python Tutorials and Resources digioz Other Languages 2 02-08-09 11:14 PM
Need help finding PHP code errors Elle0000 PHP 4 10-08-06 01:31 PM
Converting VB6 script to Python LAMPX The Lounge 0 04-11-06 05:51 PM
Explanation of Code... Please davidk19380 Perl 1 02-26-06 01:50 PM
execute code - then mail()... HOW?? nassau PHP 4 03-04-05 08:59 AM


All times are GMT -5. The time now is 03:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.