Dec 2, 2019 01:31 PM
(This post was last modified: Dec 2, 2019 01:35 PM by Formula 1.)
Hello,
can someone tell me how can i read from txt file (which is on directlink website) line by line?
I have on the txt file some list of codes for example:
XXXX-XXXX-XXXX-XXXX
YYYY-YYYY-YYYY-YYYY
If one of these codes is exist, do something
Dec 2, 2019 02:00 PM
(This post was last modified: Dec 2, 2019 02:08 PM by MavenGradle.)
Since the data you're after is located online (if I understand correctly), you should consider using a WebClient or HttpWebRequest to retrieve said information.
https://docs.microsoft.com/en-us/dotnet/...mework-4.8
https://docs.microsoft.com/en-us/dotnet/...mework-4.8
After which you can split the content into multiple parts (which I would not recommend due to there being an overhead there that can be avoided) or if you're reading it as a stream, you can simply read the stream line by line:
https://docs.microsoft.com/en-us/dotnet/...mework-4.8
Obviously, it would be recommended to perform these operations asynchronously as to not block the user interface, if there's a need for that.
https://docs.microsoft.com/en-us/dotnet/...pts/async/
Also, if this is an attempt at protecting your application from cracking, this is not an appropriate way to handle this.
Thanks for your reply,
I tried this already but its not working good.
it works only for the first line, if the correct code was the second line it doesnt recognize it.
It would be helpful if you posted your code so that we could take a look at it.
Code private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://********/hwid.txt");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
if (content.Equals(textBox2.Text))
{
MessageBox.Show("Exists);
}
else
{
MessageBox.Show("Doesn't Exists);
}
}
Dec 2, 2019 02:18 PM
(This post was last modified: Dec 2, 2019 02:23 PM by MavenGradle.)
(Dec 2, 2019 02:14 PM)Formula 1 Wrote: Code private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://********/hwid.txt");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
if (content.Equals(textBox2.Text))
{
MessageBox.Show("Exists);
}
else
{
MessageBox.Show("Doesn't Exists);
}
}
You're reading the content of the stream to the end and comparing the entire result to the content of your textbox which is not something you want since this file you're reading from the WebClient Stream contains multiple lines and you need to have only a single hit and not having the entire content match.
Instead, try reading the stream line by line and comparing the results:
https://docs.microsoft.com/en-us/dotnet/...-at-a-time
Might I also suggest that you implement proper variable and method naming and implement error handling in case your application fails to retrieve said data or read the stream:
https://docs.microsoft.com/en-us/dotnet/...em_String_
https://docs.microsoft.com/en-us/dotnet/...mework-4.8
Good luck!
pfff getting an error.
any help boys?
(Dec 2, 2019 05:49 PM)Formula 1 Wrote: pfff getting an _error_.
any help boys?
Sure, what's the error you're getting at the moment or is it still the same one?
I do it like this,
Code for each line in content.split(newline, stringsplitoption.none)
// code
next
do not copy, i just write this in mobile.
You need to setup a loop which would try the line(i) of textbox2.text against the line(j) in the list you took from the web.
for i=1:size(textbox2.text)
for j=1:size(OnlineList)
if TextBox2.Text(i) == OnlineList(i)
% DO something
end
end
The above code is in MatLab code, I am just giving you the idea / concept how to handle it.
Dec 3, 2019 03:29 PM
(This post was last modified: Dec 3, 2019 03:37 PM by 0xDEAD10CC.)
(Dec 3, 2019 03:29 AM)Accord Wrote: I do it like this,
Code for each line in content.split(newline, stringsplitoption.none)
// code
next
do not copy, i just write this in mobile.
There is absolutely no point in reading all of the data to split it up after and read line by line, if you can read the stream line by line...
(Dec 3, 2019 02:48 PM)N1nj4Styl3 Wrote: You need to setup a loop which would try the line(i) of textbox2.text against the line(j) in the list you took from the web.
for i=1:size(textbox2.text)
for j=1:size(OnlineList)
if TextBox2.Text(i) == OnlineList(i)
% DO something
end
end
The above code is in MatLab code, I am just giving you the idea / concept how to handle it.
You misunderstood the problem described in this thread and provided a completely unhelpful code sample. What you posted describes the psuedocode for a trivial part of the finished solution when OP hasn't even gotten that far. There would be better functions to call anyways opposed to this if he had a reference to the collection to check and read lines from the stream (since they could be done at the same time).
Psuedocode:
Code stream = httpresponse
while (!eof(stream)) {
line = stream.readline()
if (keys.contains(line))
// do something
}
@OP - Post any errors or code changes you make so we can follow along faster. All you had to do in this case if you insist on using a WebClient over the modern HttpClient, was read the StreamReader stream with the ReadLine() method until EOF. (The function will return null in that case.)
(Dec 3, 2019 03:29 PM)0xDEAD10CC Wrote: There is absolutely no point in reading all of the data to split it up after and read line by line, if you can read the stream line by line...
You misunderstood the problem described in this thread and provided a completely unhelpful code sample. What you posted describes the psuedocode for a trivial part of the finished solution when OP hasn't even gotten that far. There would be better functions to call anyways opposed to this if he had a reference to the collection to check and read lines from the stream (since they could be done at the same time).
Psuedocode:
Code stream = httpresponse
while (!eof(stream)) {
line = stream.readline()
if (keys.contains(line))
// do something
}
@OP - Post any errors or code changes you make so we can follow along faster. All you had to do in this case if you insist on using a WebClient over the modern HttpClient, was read the StreamReader stream with the ReadLine() method until EOF. (The function will return null in that case.) Thank you, i will now used this instead of my previous post. this really help me.
I would probably do something like this just for a quick program
(Dec 2, 2019 02:14 PM)Formula 1 Wrote: Code private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://********/hwid.txt");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
if (content.Equals(textBox2.Text))
{
MessageBox.Show("Exists);
}
else
{
MessageBox.Show("Doesn't Exists);
}
}
Not sure if you still need this, but pretty basic shi lol.. So many better ways you can do HWID authentication, but you can test this code by copying those numbers in the raw pastebin. Assuming this is what you wanted. ❓
(Dec 5, 2019 12:53 AM)ehJoe Wrote: Not sure if you still need this, but pretty basic shi lol.. So many better ways you can do HWID authentication, but you can test this code by copying those numbers in the raw pastebin. Assuming this is what you wanted. ❓
For pretty basic shit, I wonder why you're using string.Contains to check the entire content of the file.. You're opening yourself up to a serious flaw and it's a serious overhead that can be done better, which has already been explained multiple times on this thread now.
|