Pages:
Author

Topic: Python scripting - page 2. (Read 2584 times)

full member
Activity: 169
Merit: 100
August 17, 2016, 05:46:46 PM
#21
No, like it is is great i'll give it a try now, just need to figure out how i reach the local host.

Then i'll give you a reply.

But THANK YOU VERY MUCH!!!
hero member
Activity: 1344
Merit: 656
August 17, 2016, 05:43:28 PM
#20
then i need the prefix address in each line right?

If your txt file is like:
Code:
first_addr
second_addr
.....
last_addr
the code will work.

The github code seems to loop through lines which are prefixed with Address: and Privkey: but if your file contains only addresses, one per line, then the code will work just fine (it loops through the lines and affects the line's value to the variable address). Is this case? Or will you also have private keys in your txt file?
full member
Activity: 169
Merit: 100
August 17, 2016, 05:37:51 PM
#19
then i need the prefix address in each line right?
hero member
Activity: 1344
Merit: 656
August 17, 2016, 05:29:58 PM
#18
I want to put the addresses in a textfile.

Let's assume there is one address per line, then you might replace the previous loop with:

Code:
f = open("addresses.txt", "r")

for address in f:
....

And if you want to write the results somewhere then use:

Code:
f = open("balances.txt", "w")

f.write(....)

Finally you might have something like:

Code:
addresses = open("addresses.txt", "r")
balances = open("balances.txt", "w")

for address in addresses:
    urlRequest = urllib2.Request("http://localhost:3001/insight/" + address)
    data = urllib2.urlopen(urlRequest).read()
    json_data = json.loads(data)
    balances.write("Balance of " + address + " is " + str(json_data["data"]["balance"]) + "\n") #use the right keys

addresses.close()
balances.close()
hero member
Activity: 1344
Merit: 656
August 17, 2016, 05:24:29 PM
#17
Yes, these works great!

But need it to read the addresses from a list.

Then you might loop through your list, something like that:

Code:
balances = []

for address in addresses:
    urlRequest = urllib2.Request("https://blockchain.info/rawaddr/" + address)
    data = urllib2.urlopen(urlRequest).read()
    json_data = json.loads(data)
    balances.append("Balance of " + address + " is " + str(json_data['final_balance']))

"\n".join(balances)
full member
Activity: 169
Merit: 100
August 17, 2016, 05:22:06 PM
#16
I want to put the addresses in a textfile.
The output is ok.
Url supposed to be: http://localhost:3001/insight/ (not working right now)
hero member
Activity: 1344
Merit: 656
August 17, 2016, 05:16:39 PM
#15
Maybe you got an easy clean solution, to check the balance of some addresses in a list, on a local node?

If it is parsing the output of a url to get the balance then I think it can be done.

I just need some info:
- Where are the addresses? in a file? in the code in a list object?
- What is the call you perform for the local node i.e. the url which you use to access information about the BTC address? And do you expect the same kind of output that http://btc.blockr.io/api/v1/address/info/
gives?

full member
Activity: 169
Merit: 100
August 17, 2016, 05:14:57 PM
#14
Yes, these works great!

But need it to read the addresses from a list.
sr. member
Activity: 292
Merit: 251
Telegram: @Adriandmen
August 17, 2016, 05:09:12 PM
#13
Maybe you got an easy clean solution, to check the balance of some addresses in a list, on a local node?

Cause the script from github has got much crap in it!
https://github.com/TheZ3ro/bitcoin-privkey-bruteforce/blob/master/btcscan.py

This one also works:

Code:
import urllib2
import json

address = raw_input("Enter Address >> ")
urlRequest = urllib2.Request("https://blockchain.info/rawaddr/" + address)
data = urllib2.urlopen(urlRequest).read()

json_data = json.loads(data)
print "Final Balance: " + str(json_data['final_balance'])
hero member
Activity: 1344
Merit: 656
August 17, 2016, 05:04:34 PM
#12
Just an error: unexpected indent

So there seem to be an issue with indentation, maybe a mix of tabs and spaces ...

Did you try running the lines directly in a python interpreter, like this:

Code:
import urllib2
import json
address = "your_address"
req = urllib2.Request("http://btc.blockr.io/api/v1/address/info/"+address)
res = urllib2.urlopen(req)
print res.read()
json_data = json.load(res)
print json_data
full member
Activity: 169
Merit: 100
August 17, 2016, 04:58:31 PM
#11
Maybe you got an easy clean solution, to check the balance of some addresses in a list, on a local node?

Cause the script from github has got much crap in it!
https://github.com/TheZ3ro/bitcoin-privkey-bruteforce/blob/master/btcscan.py
full member
Activity: 169
Merit: 100
August 17, 2016, 04:51:32 PM
#10
Just an error: unexpected indent
hero member
Activity: 1344
Merit: 656
August 17, 2016, 04:45:48 PM
#9
The code like it is, works, just when i try to point it to my localhost, nothing happens

What does print res.read() return?
full member
Activity: 169
Merit: 100
August 17, 2016, 04:31:28 PM
#8
ATM i'm using python 2.7.12

i copied these line from github from a script. Tried to modify it, but till now nothing worked.

If i'm typing an addres in the browser, the node works fine.

Edit:
The code like it is, works, just when i try to point it to my localhost, nothing happens




hero member
Activity: 1344
Merit: 656
August 17, 2016, 04:16:07 PM
#7
The original code seems okay to me, though there are somethings that bother me:
- The scan function has a parameter named pkey which it doesn't use ...
- I don't know why +"" is added.
- urlopen can directly take the (string) url as parameter, I don't see why call Request first ...

Normally, both json.load(res) and json.loads(res.read()) should work ...

What version of python are you using?

Do you get an exception when running your code?

full member
Activity: 169
Merit: 100
August 17, 2016, 03:37:14 PM
#6
Thx again, but nothing worked!

I think i'm doing somthing wrong with the Url and the json_data quering.
legendary
Activity: 1612
Merit: 1608
精神分析的爸
August 17, 2016, 03:09:13 PM
#5
I don't know about insight api, however what I said regarding txindex is wrong: that doesn't give you the ability query balances, just all transactions (from which you can extract all balances if you for example store them in a db like a block explorer does).
sr. member
Activity: 292
Merit: 251
Telegram: @Adriandmen
August 17, 2016, 02:36:16 PM
#4
The syntax seems wrong. I'm assuming this is Python 2.

I haven't tested it yet, but does the following work?:

Code:
req = urllib2.Request("http://btc.blockr.io/api/v1/address/info/"+address)
res = urllib2.urlopen(req)
json_data = json.loads(res.read())
full member
Activity: 169
Merit: 100
August 17, 2016, 02:28:53 PM
#3
First thx for your reply, but
how should the code lines look then?

It's a bitcored full node with insight api, so think -txindex is not suitable?

legendary
Activity: 1612
Merit: 1608
精神分析的爸
August 17, 2016, 02:13:36 PM
#2
If you want to check against your local node, the below python module would probably be better suited for the job (though it probably can be done in some more complicated way with urllib2):

https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#Python

Also AFAIK to query the balance of any address and not just those of your wallet you'd need to run the node with -txindex, see below URL:

https://en.bitcoin.it/wiki/Running_Bitcoin

HTH
Pages:
Jump to: