This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PixelFox's profile picture

How to get the pastebin "nfsfd89" part?

Started by PixelFox, 07 July 2015 - 04:11 PM
PixelFox #1
Posted 07 July 2015 - 06:11 PM
I've been working on an antivirus, and I want users to be able to send the virus to me, via pastebin, but, I do not know how to get the "spaD8K9" part

It would work like this:

– Computer Uploads Code To Pastebin –
– Sends me the Pastebin Identifier via Rednet – This, how would I do this, how do I get the Identifier? e.x (6Si9H02)
– My automatic system downloads it as "Virus0024" –
– I get the virus to add to my Anti-virus –

Help please, it outputs true instead of what I want it too.
Code: pastebin.com/HZpgSwe6
Edited on 07 July 2015 - 04:58 PM
InDieTasten #2
Posted 07 July 2015 - 06:21 PM
Take a look into the pastebin program ;)/> Theres an output of the identifier, which you need to extract. I would copy the upload section of the program to my own and remove the output to the terminal, and send the identifier via rednet instead. The receiving computer just needs to call pastebin get id Virus0024 and there you have it.
InDieTasten #3
Posted 07 July 2015 - 06:28 PM
As to your example or usage of that, I don't think anti-virus software makes a lot of sense in computercraft. It's really hard to do, and I can't think of a scenario, where you rely on something like this, as even real anti virus software is hardly any better than the normal OS security. I don't want you to stop your project, it's still cool to have done something like this, but just be aware of that.
PixelFox #4
Posted 07 July 2015 - 06:54 PM
Um, can I have an example, it keeps outputting true, instead of what I want.
HPWebcamAble #5
Posted 07 July 2015 - 07:09 PM
From the Pastebin program that comes with CC:

local sCommand = tArgs[1]
if sCommand == "put" then
    -- Upload a file to pastebin.com
    -- Determine file to upload
    local sFile = tArgs[2]
    local sPath = shell.resolve( sFile )
    if not fs.exists( sPath ) or fs.isDir( sPath ) then
        print( "No such file" )
        return
    end

    -- Read in the file
    local sName = fs.getName( sPath )
    local file = fs.open( sPath, "r" )
    local sText = file.readAll()
    file.close()

    -- POST the contents to pastebin
    write( "Connecting to pastebin.com... " )
    local key = "0ec2eb25b6166c0c27a394ae118ad829"
    local response = http.post(
        "http://pastebin.com/api/api_post.php", 
        "api_option=paste&"..
        "api_dev_key="..key.."&"..
        "api_paste_format=lua&"..
        "api_paste_name="..textutils.urlEncode(sName).."&"..
        "api_paste_code="..textutils.urlEncode(sText)
    )

    if response then
        print( "Success." )

        local sResponse = response.readAll()
        response.close()

        local sCode = string.match( sResponse, "[^/]+$" )
        print( "Uploaded as "..sResponse )
        print( "Run \"pastebin get "..sCode.."\" to download anywhere" )

    else
        print( "Failed." )
    end

elseif sCommand == "get" then

Also, the pastebin you posted has been removed on PB
PixelFox #6
Posted 08 July 2015 - 03:13 PM
Someone tell me how to do this, I'm really confused.
KingofGamesYami #7
Posted 08 July 2015 - 03:28 PM
Let's break it down, shall we?


if sCommand == "put" then
    -- Upload a file to pastebin.com
    -- Determine file to upload
    local sFile = tArgs[2]
    local sPath = shell.resolve( sFile )
    if not fs.exists( sPath ) or fs.isDir( sPath ) then
        print( "No such file" )
        return
    end
Bla bla bla, determining where the file is


    -- Read in the file
    local sName = fs.getName( sPath )
    local file = fs.open( sPath, "r" )
    local sText = file.readAll()
    file.close()
Reading the contents of the file

    -- POST the contents to pastebin
    write( "Connecting to pastebin.com... " )
    local key = "0ec2eb25b6166c0c27a394ae118ad829"
    local response = http.post(
        "http://pastebin.com/api/api_post.php", 
        "api_option=paste&"..
        "api_dev_key="..key.."&"..
        "api_paste_format=lua&"..
        "api_paste_name="..textutils.urlEncode(sName).."&"..
        "api_paste_code="..textutils.urlEncode(sText)
    )
POSTing the contents to pastebin's API, store the result


    if response then
        print( "Success." )

        local sResponse = response.readAll()
        response.close()

        local sCode = string.match( sResponse, "[^/]+$" )
        print( "Uploaded as "..sResponse )
        print( "Run \"pastebin get "..sCode.."\" to download anywhere" )
if we got a response, read the string returned and match all characters from the end of the string that are not a slash (/) The string will look something like this: "http://www.pastebin.com/eaf465", from which string.match gets "eaf465".

    else
        print( "Failed." )
    end
If we didn't get a response, the file wasn't uploaded!
PixelFox #8
Posted 08 July 2015 - 04:24 PM
Let's break it down, shall we?


if sCommand == "put" then
	-- Upload a file to pastebin.com
	-- Determine file to upload
	local sFile = tArgs[2]
	local sPath = shell.resolve( sFile )
	if not fs.exists( sPath ) or fs.isDir( sPath ) then
		print( "No such file" )
		return
	end
Bla bla bla, determining where the file is


	-- Read in the file
	local sName = fs.getName( sPath )
	local file = fs.open( sPath, "r" )
	local sText = file.readAll()
	file.close()
Reading the contents of the file

	-- POST the contents to pastebin
	write( "Connecting to pastebin.com... " )
	local key = "0ec2eb25b6166c0c27a394ae118ad829"
	local response = http.post(
		"http://pastebin.com/api/api_post.php",
		"api_option=paste&"..
		"api_dev_key="..key.."&"..
		"api_paste_format=lua&"..
		"api_paste_name="..textutils.urlEncode(sName).."&"..
		"api_paste_code="..textutils.urlEncode(sText)
	)
POSTing the contents to pastebin's API, store the result


	if response then
		print( "Success." )

		local sResponse = response.readAll()
		response.close()

		local sCode = string.match( sResponse, "[^/]+$" )
		print( "Uploaded as "..sResponse )
		print( "Run \"pastebin get "..sCode.."\" to download anywhere" )
if we got a response, read the string returned and match all characters from the end of the string that are not a slash (/) The string will look something like this: "http://www.pastebin.com/eaf465", from which string.match gets "eaf465".

	else
		print( "Failed." )
	end
If we didn't get a response, the file wasn't uploaded!
I get that, I already tried that.
I used "return sCode", and I only got true or false when I did

a = shell.run("Uploader put Uploader")
print(a)
Lyqyd #9
Posted 08 July 2015 - 05:36 PM
That's because shell.run only ever returns true or false. Why are you using a shell.run call there instead of the code you've been getting help with above?
biggest yikes #10
Posted 09 July 2015 - 03:06 PM
Judging from the replies, this might as well be an xy situation. shell.run returns if it was successful or not, programs can't define their result. just try everyone else's code, they should work fine
Edited on 09 July 2015 - 01:20 PM
H4X0RZ #11
Posted 09 July 2015 - 05:23 PM
Just for completeness, you could also do it the "hacky" way:


local oldPrint = print
local oldWrite = write
local line = ""
write = function() end
print = function(text) line = text end

local filename = "path/to/file"
shell.run("pastebin","put",filename)

local code = string.match(line,"Run \"pastebin get (.+)\" to download anywhere")

print = oldPrint 
write = oldWrite

print(code)