Last active
April 19, 2019 05:40
-
-
Save lontivero/3fcc9cbb145a427fbae305ece873c516 to your computer and use it in GitHub Desktop.
Get Bitcoin nodes on onion domains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace seeds | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var list = await GetAsync(); | |
} | |
private static async Task<List<string>> GetAsync() | |
{ | |
var ret = new List<string>(); | |
using (var httpClient = new HttpClient()) | |
{ | |
httpClient.BaseAddress = new Uri("https://bitnodes.21.co/api/v1/"); | |
using (var response = await httpClient.GetAsync("snapshots/latest/", HttpCompletionOption.ResponseContentRead)) | |
{ | |
if (response.StatusCode != HttpStatusCode.OK) | |
throw new HttpRequestException(response.StatusCode.ToString()); | |
var responseString = await response.Content.ReadAsStringAsync(); | |
var json = (JObject)JsonConvert.DeserializeObject(responseString); | |
foreach(JProperty node in json["nodes"]) | |
{ | |
if( !node.Name.ToString().Contains(".onion") ) | |
continue; | |
var userAgent = ((JArray)node.Value)[1].ToString(); | |
if( userAgent.Contains("Satoshi:0.16") || userAgent.Contains("Satoshi:0.17")) | |
{ | |
ret.Add(node.Name); | |
} | |
} | |
} | |
} | |
return ret; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Net.Sockets; | |
using System.Threading.Tasks; | |
namespace seeds | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var dns = new [] | |
{ | |
"testnet-seed.bitcoin.jonasschnelli.ch", | |
"seed.tbtc.petertodd.org", | |
"seed.testnet.bitcoin.sprovoost.nl", | |
"testnet-seed.bluematt.me", | |
}; | |
var hs = new HashSet<IPAddress>(); | |
var i = 0; | |
while(true) | |
{ | |
var source = dns[i++ % dns.Length]; | |
try{ | |
var dnsServer = Dns.GetHostAddresses(source); | |
foreach(var ip in dnsServer.Where(x=>x.AddressFamily==AddressFamily.InterNetworkV6)) | |
{ | |
if(hs.Contains(ip)) continue; | |
var bytes = ip.GetAddressBytes(); | |
if(bytes[0] == 0xfd && bytes[1] == 0x87){ | |
Console.WriteLine(ip.ToString()); | |
hs.Add(ip); | |
} | |
} | |
await Task.Delay(3000); | |
} | |
catch(Exception) | |
{ | |
Console.WriteLine("Error: " + source); | |
await Task.Delay(1000); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment