added script to find peers
This commit is contained in:
parent
3cce122fb2
commit
bf895d03c3
25
bit.js
Normal file
25
bit.js
Normal file
@ -0,0 +1,25 @@
|
||||
var Tracker = require('bittorrent-tracker')
|
||||
var magnet = require('magnet-uri')
|
||||
|
||||
var magnetURI = "magnet:?xt=urn:btih:08122dc39c46fab0221aa24e93f2825e3f9efe61&dn=%5BAndreas_M._Antonopoulos%5D_Mastering_Bitcoin_Progr(b-ok.org).pdf&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com"
|
||||
|
||||
var parsedTorrent = magnet(magnetURI)
|
||||
//console.log(parsedTorrent);
|
||||
|
||||
|
||||
var opts = {
|
||||
infoHash: parsedTorrent.infoHash,
|
||||
announce: parsedTorrent.announce,
|
||||
peerId: new Buffer('2d5757303030322d773974324137436b54727a30'), // hex string or Buffer
|
||||
port: 6881 // torrent client port
|
||||
}
|
||||
|
||||
|
||||
var client = new Tracker(opts)
|
||||
|
||||
client.scrape()
|
||||
|
||||
client.on('scrape', function (data) {
|
||||
console.log(data)
|
||||
})
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"bitcoin-core": "^2.0.0",
|
||||
"bittorrent-tracker": "^9.10.1",
|
||||
"body-parser": "^1.18.3",
|
||||
"bootstrap": "^4.1.3",
|
||||
"browserify": "^16.2.2",
|
||||
@ -19,6 +20,7 @@
|
||||
"jquery": "^3.3.1",
|
||||
"jquery-ui": "^1.12.1",
|
||||
"lodash": "^4.17.10",
|
||||
"magnet-uri": "^5.2.3",
|
||||
"npm": "^6.3.0",
|
||||
"popper.js": "^1.14.4",
|
||||
"watchify": "^3.11.0",
|
||||
|
||||
41
routes.js
41
routes.js
@ -11,6 +11,9 @@ const funcs = require('./public/js/funcs')
|
||||
var path = require('path')
|
||||
var fs = require('fs');
|
||||
|
||||
var Tracker = require('bittorrent-tracker')
|
||||
var magnet = require('magnet-uri')
|
||||
|
||||
//const JSON = require('circular-json');
|
||||
|
||||
router.get('/', (req, res)=>{
|
||||
@ -248,4 +251,42 @@ router.post('/fetch-from-blockchain', [
|
||||
|
||||
})
|
||||
|
||||
router.get('/trackers-list', (req, res)=>{
|
||||
res.render('trackers-list', {
|
||||
data: {},
|
||||
errors: {},
|
||||
title: 'Trackers List'
|
||||
})
|
||||
})
|
||||
|
||||
router.post('/trackers-list', (req, res)=>{
|
||||
let params = _.pick(req.body, ['job', 'mag_url', 'pid'])
|
||||
if (params.job!=="track list") {
|
||||
return;
|
||||
}
|
||||
|
||||
let magnetURI = params.mag_url
|
||||
let peer_id = params.pid
|
||||
|
||||
var parsedTorrent = magnet(magnetURI)
|
||||
|
||||
var opts = {
|
||||
infoHash: parsedTorrent.infoHash,
|
||||
announce: parsedTorrent.announce,
|
||||
peerId: new Buffer(peer_id), // hex string or Buffer
|
||||
port: 6881 // torrent client port
|
||||
}
|
||||
|
||||
var client = new Tracker(opts)
|
||||
|
||||
client.scrape()
|
||||
|
||||
client.on('scrape', function (data) {
|
||||
console.log("1")
|
||||
res.write(JSON.stringify(data))
|
||||
})
|
||||
//res.end()
|
||||
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@ -1,7 +1,7 @@
|
||||
<%include partials/header.ejs %>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<!-- duckdns-> oVrbkDUrX727MjQd4zq7nRw1XEHkkpGErE -->
|
||||
<label for="flo-addr">Enter the flo address (oSjBiuTE1aFNBjaSGq6UNhU9ddpD2YXdg8)</label>
|
||||
<input type="text" id="flo-addr" class="form-control" />
|
||||
|
||||
@ -24,8 +24,6 @@
|
||||
<%include partials/footer.ejs %>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
$(document).on('click', '#flo-addr-btn', function() {
|
||||
var floaddr = $("#flo-addr").val();
|
||||
if (floaddr.length<1) {
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
<li><a href="/download-magnetic-uri">Download Torrent from Magnetic URL</a></li>
|
||||
<li><a href="/send-to-blockchain">Send Magnetic URL to FLO Blockchain</a></li>
|
||||
<li><a href="/fetch-from-blockchain">Download torrent from FLO Blockchain</a></li>
|
||||
<li><a href="/trackers-list">List of trackers</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@ -40,15 +40,17 @@ let seeding = () => {
|
||||
|
||||
t += `<p>Name: ${torrent.name}</p>`;
|
||||
t += `<p>Path: ${torrent.path}</p>`;
|
||||
t += `<p><strong>peerId: ${torrent.client.peerId}</strong></p>`;
|
||||
t += `<p><strong>infoHash: ${torrent.infoHash}</strong></p>`;
|
||||
var hexdata = torrent.torrentFile.toString('hex');
|
||||
t += `<p>Torrent: ${hexdata}</p>`;
|
||||
t += `<p></p>`;
|
||||
|
||||
t += `<h5>Files hash</h5>`;
|
||||
for (let h = 0; h < torrent._hashes.length; h++) {
|
||||
const hash = torrent._hashes[h];
|
||||
t += `<p>${hash}</p>`;
|
||||
}
|
||||
// t += `<h5>Files hash</h5>`;
|
||||
// for (let h = 0; h < torrent._hashes.length; h++) {
|
||||
// const hash = torrent._hashes[h];
|
||||
// t += `<p>${hash}</p>`;
|
||||
// }
|
||||
|
||||
t += `<h5>Peers</h5>`;
|
||||
for (let p = 0; p < torrent._peers.length; p++) {
|
||||
|
||||
45
views/trackers-list.ejs
Normal file
45
views/trackers-list.ejs
Normal file
@ -0,0 +1,45 @@
|
||||
<%include partials/header.ejs %>
|
||||
|
||||
<div class="container">
|
||||
<h1>Get list of trackers</h1>
|
||||
|
||||
<label for="pid">Peer Id:</label>
|
||||
<input type="text" class="form-control" id="pid">
|
||||
|
||||
<label for="mag_url">Provide a valid magnetic url:</label>
|
||||
<textarea id="mag_url" cols="30" rows="10" class="form-control"></textarea>
|
||||
|
||||
<button type="submit" id="btn-tk" class="btn btn-primary">Hit</button>
|
||||
|
||||
<div id="tl-res" style="padding: 5rem 5rem"></div>
|
||||
</div>
|
||||
|
||||
<%include partials/footer.ejs %>
|
||||
|
||||
<script>
|
||||
$(document).on("click", "#btn-tk", function() {
|
||||
var mag_url = $("#mag_url").val();
|
||||
var job = "track list";
|
||||
var pid = $("#pid").val();
|
||||
|
||||
$("#tl-res").text("Getting information from the server...it can takes few minutes.");
|
||||
|
||||
$.ajax({
|
||||
url:'/trackers-list',
|
||||
type:'post',
|
||||
data:{job:job, mag_url:mag_url, pid:pid},
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
if (data.length>0) {
|
||||
$("#tl-res").text(data);
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user