-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNiceHase_API.cs
More file actions
132 lines (114 loc) · 4.16 KB
/
NiceHase_API.cs
File metadata and controls
132 lines (114 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Timers;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.ComponentModel;
namespace ConsoleApp1
{
class Program
{
static Timer myTimer = new System.Timers.Timer();
static DateTime TimeNow;
static byte Count;
static Boolean IsOk = true;
static string wallet = "35HUFFdAKdVpKFXm9Yj7N3FQGFVWwcPvRt";
static void Main(string[] args)
{
myTimer.Elapsed += timer1_Tick;
myTimer.Interval = 1 * 60 * 1000;
myTimer.Start();
Console.WriteLine("Работаю");
TimeNow = DateTime.Now;
string sTimeNow = TimeNow.ToString();
Console.WriteLine(sTimeNow.Substring(11, 5));
GetAndShowSpeed(wallet);
Console.WriteLine("Press the Enter key to exit the program at any time... ");
Console.ReadLine();
}
public static void GetAndShowSpeed(string Wallet)
{
string Answer = GetNiceHashAPI(Wallet);
// richTextBox1.Text = Answer;
int iNumStart, iNumEnd;
string sFind = "\"a\":";
iNumStart = Answer.IndexOf(sFind);
string subAnswer, Speed;
if (iNumStart > 0)
{
iNumEnd = Answer.IndexOf("\"}", iNumStart);
subAnswer = Answer.Substring(iNumStart + 5, iNumEnd - iNumStart - 5);
Speed = subAnswer;
}
else
{
Speed = "ФЕРМА СТОИТ!";
IsOk = false;
Count += 1;
myTimer.Stop();
myTimer.Interval = 1 * 60 * 1000;
myTimer.Start();
if (Count > 3)
{// Обработка остановки фермы
Console.WriteLine("Ферма стоит!!!");
Console.WriteLine("Ищу watchdoginua");
var process = Process.GetProcessesByName("watchdoginua");
foreach (var proc in process)
{
Console.WriteLine(proc.ProcessName);
proc.Kill;
}
}
}
if (IsOk)
{
Console.WriteLine("Текущая скорость: {0} H/sec", Speed);
Count = 0;
myTimer.Stop();
myTimer.Interval = 5 * 60 * 1000;
myTimer.Start();
}
else
{
Console.WriteLine(Speed);
Console.WriteLine(" {0} Проход", Count.ToString());
}
}
private static string GetNiceHashAPI(string BTCaddr)
{
string HTTPS_URL = "https://api.nicehash.com/api";
var postData = "?method=stats.provider.workers";
postData += "&addr=" + BTCaddr;
HTTPS_URL += postData;
var data = Encoding.ASCII.GetBytes(postData);
// richTextBox1.Text = postData;
// richTextBox1.Text += Convert.ToChar(13);
var request = (WebRequest)WebRequest.Create(HTTPS_URL);
request.ContentType = "application/json"; // x - www - form - urlencoded";
request.Method = "POST";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
stream.Close();
}
var response = (WebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
response.Close();
string answer = responseString.Substring(0);
return answer;
}
private static void timer1_Tick(object sender, EventArgs e)
{
TimeNow = DateTime.Now;
string sTimeNow = TimeNow.ToString();
Console.WriteLine(sTimeNow);
GetAndShowSpeed(wallet);
}
}
}