Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Pastebin Client, download, paste (from file or data)

PHP Code

<?php 
import urllib
import sys
import md5
import urlparse
import urllib2

key 
= "d974f286bc3bf50c7de439ca395b7a8f"
url = "http://pastebin.com/api/api_post.php"

def usage():
    print(
'Usage:    ')
    print(
'  %s download pastebin.com/NXaHrrEs pastebin.com/7PfbBGR4' % sys.argv[0])
    print(
'  %s paste file C:\\boot.ini' % sys.argv[0])
    print(
'  %s paste Data you want to send.' % sys.argv[0])
    print(
'\n Made by Hannah Montana/obnoxious')
    
sys.exit()

if 
len(sys.argv) == 1 or len(sys.argv) == 2:
    
usage()

if 
'help' in sys.argv[1]:
    
usage()

if 
'download' in sys.argv[1]:
    for 
i in range(len(sys.argv)):
        if 
sys.argv[i].count('/') >= 3 and i != 0 and i != 1:
            
url = sys.argv[i].split('/')[3]
            
urllib.urlretrieve('http://pastebin.com/raw.php?i=%s' % url, url)
            print(
'%s has finished downloading.' % url)
        
elif sys.argv[i].count('/') >= 1 and i !=0 and i != 1:
            
url = sys.argv[i].split('/')[1]
            
urllib.urlretrieve('http://pastebin.com/raw.php?i=%s' % url, url)
            print(
'%s has finished downloading.' % url)

if 
'paste' in sys.argv[1]:
    if 
'file' in sys.argv[2]:
        
fileData = open(sys.argv[3], 'r').read()
        
data = {}
        
data["api_dev_key"] = key
        data
["api_option"] = "paste"
        
data["api_paste_name"] = md5.md5(fileData).hexdigest()
        
data["api_paste_code"] = fileData
        data
["api_paste_private"] = sys.argv[4]
        
urlEncode = urllib.urlencode(data).encode("utf8")
        
resultUrl = urllib2.urlopen(url, urlEncode).read().decode("utf-8")

        print 
resultUrl

    
else:
        
pasteData = sys.argv[2:]
        
data = {}
        
data["api_dev_key"] = key
        data
["api_option"] = "paste"
        
data["api_paste_name"] = md5.md5(''.join(pasteData)).hexdigest()
        
data["api_paste_code"] = ' '.join(pasteData)
        
data["api_paste_private"] = 1
        urlEncode 
= urllib.urlencode(data).encode("utf8")
        
resultUrl = urllib2.urlopen(url, urlEncode).read().decode("utf-8")

        print 
resultUrl 

I barrowed some code from jhpy (the guy who made pyPaste, The API key isn't mine it's his. His fault for putting it on github lel.)

How to use
pastebinClient.py help
Haha, thanks for stealing my API key :D

Good little tool anyway :)
I wouldn't say it's bad, but it also isn't good.

Don't steal code/API keys :/
(Jun 5, 2013 02:21 PM)glob Wrote:  I wouldn't say it's bad, but it also isn't good.

Don't steal code/API keys :/

He didn't really steal it, we were talking on irc and basically let him use it.
It doesn't matter if you let him or not, he is releasing your code :p
(Jun 5, 2013 02:36 PM)glob Wrote:  It doesn't matter if you let him or not, he is releasing your code :p

Haha, technically he released his own code. Even if he went back and changed it in the GitHub repo, I'm pretty sure people can view the entire history of every change in the code, which would include the one in which he removed it.
(Jun 5, 2013 02:36 PM)glob Wrote:  It doesn't matter if you let him or not, he is releasing your code :p

The only code I used from him was the pastebin API usage and there is nothing wrong with releasing the code with permission.

EDIT: I could have made it quite a bit better too now looking at it but meh.
(Jun 5, 2013 05:11 PM)Hannah Montana Wrote:  The only code I used from him was the pastebin API usage and there is nothing wrong with releasing the code with permission.

EDIT: I could have made it quite a bit better too now looking at it but meh.

You don't learn anything if you release other people's code whether you have permission or not.
(Jun 5, 2013 06:18 PM)glob Wrote:  You don't learn anything if you release other people's code whether you have permission or not.

I don't learn anything? I learned from reading it.
Good work. Thank you for share brother.
Code
def usage():
    print('''Usage:    
{0} download pastebin.com/NXaHrrEs pastebin.com/7PfbBGR4
{0} paste file C:\\boot.ini
{0} paste Data you want to send
{0} Made by Hannah Montana/obnoxious'''.format(sys.argv[0]))
    exit()

Look into using argparse module.

It will allow you to type "$python scriptname.py -h" and it will automatically give the user information on the command line arguments


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by __init__Jul 19, 2018 01:08 AM 24 1,187 Jul 19, 2018 01:08 AM
Last Post: Lucky83
[C#] by TrinityAug 21, 2017 06:33 PM 23 1,084 Aug 21, 2017 06:33 PM
Last Post: DeadKube
[Shell] by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™Apr 2, 2017 07:18 AM 2 235 Apr 2, 2017 07:18 AM
Last Post: Hackoo