|
|
URL's passing as a question
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello to all,
I am struggling to find a way to get MAC address ONLY from the ethernet card in my PC.
It's easy when my PC is not connected on the VPN:
Function getMacAddress()
Dim nics() As NetworkInterface = _
NetworkInterface.GetAllNetworkInterfaces
Return nics(0).GetPhysicalAddress.ToString
End Function
But if it's already connected then the first (0) device is ethernet card of the server that I'm connected and my ethernet is second (1) device so I don't know how to determine.
This is showed on the image on this link: https://postimg.org/image/4ndewjjhz/
Any help is very appreciated!
|
|
|
|
|
No, it's NOT the network interface of the server you're connected to. You cannot get remote MAC adresses.
What you're getting is the MAC of the virtual network adapter created by the VPN software.
Dump the data on all the adapters returned, not just the first one.\
MAC addresses are not assigned to machines. They are assigned by the manufactures of the network adapters, or a generated in software for the adapter.
MAC's can NOT be used as a unique identifier for any purpose. They are NOT unique to any machine!
|
|
|
|
|
Hi Dave,
So what do you suggest to use as the unique identifier?
|
|
|
|
|
You didn't say thing about the type of app you're writing, but typically, I'd generate a GUID and send that to the client and it stores it appropriately, passing it back to the server as appropriate when needed.
|
|
|
|
|
Actually I have made an Windows Form application and I am trying to protect it by giving a specific activation code generated by some machine id or something like that. I read about many different ways of getting unique hardware serials but there is no perfect solution cause hardware components can be cloned or replaced. I agree with you about activation through server but I would like to make possibility to make also offline registration.
|
|
|
|
|
Honestly, the copy protection problem has never been solved, by any vendor. It's a waste of your time and, more importantly, your customers time.
My primary job is software repackaging for deployment in the enterprise environment. Trust me when I tell you, as a customer, licensing is a giant pain in the ass.
Normally, vendors use the data submitted about the customer, such as company name, contact name, phone number, address, email address, and whatnot, run all that through an algorithm to generate a license key file. That license file is checked for validity by the application on launch.
But, in all cases, if someone wanted to hack your app and take out the license validation, there's nothing you can do to stop them.
DO NOT TRY AND "ROLL YOUR OWN" LICENSING SOLUTION. You'll end up making it ridiculously easy to break. Use a commercial solution. Google for "C# licensing framework".
|
|
|
|
|
Dave,
Thank you so much for the great advice!
I will keep in mind all your words.
All the best,
Danijel
|
|
|
|
|
I'm creating a "Find In Files" application for my own use in VB.net. After seeing all the problems people have working around UnauthorizedAccess exceptions, I used a windowless call to cmd.exe to get a directory list and sent it to a text file like so:
sw.WriteLine("dir/s/b/ad >" & ChrW(34) & dataPath & ChrW(34))
This avoids directories to which I don't have access, and it's pretty fast. But since I didn't see this anywhere else, I have to assume either I'm a genius or this is a really bad idea (probably the latter).
I thought I might upload the project to CP when it's done, so my question is whether this is considered an acceptable practice or should I work on a different method of enumerating the directories?
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
"Acceptable" to who?
I would say there are more options than you may have considered; e.g. piping batch files; shell scripting; running app at admin level.
There are very few "new" ways of doing things; only existing ways that can be improved upon.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
Richard MacCutchan wrote: Why make things more complicated than they need to be?
Because this allows UnauthorizedAccess exceptions to occur. As Eddy says below, this may be due to running in debug mode. Just now getting back to the project so I'll try running it outside the debugger. Also once the directory list is created I'm using Regex to search inside files, which GetFiles doesn't support. I'm learning as I go here. Thanks.
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
You can also try one of Directory.EnumerateFileSystemEntries Method (System.IO)[^] which can list the contents of a single directory, and optionally, subdirectories.
Alan Burkhart wrote: I'm using Regex to search inside files, which GetFiles doesn't support I don't understand what that means. Once you have a list of filenames you still need to open and read each one in order to search the contents.
|
|
|
|
|
Richard MacCutchan wrote: I don't understand what that means. Once you have a list of filenames you still need to open and read each one in order to search the contents.
Just that Regex provides a few more options without slowing down the search.
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
If the Directory.GetFiles was slow for you with UnauthorizedAccessException's, then it is because there was a debugger attached.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Just now getting back to the project. Will try running outside the debugger and see what happens. Thanks.
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
Hi everybody
I want to delete lines in text file based on search criteria entered in textbox.
My text file is like this:
[account]
user = usertest
pwd = test
description = test
date = "21/03/2018"
address = "blah bla"
email = "yyyy'
[account]
user = usertest2
pwd = test2
description = test2
date = "21/03/2019"
address = "atatatta"
email = "ccccc'
when i enter in textbox (usertest) for deleting I want to delete all lines of this user.
I have tried something but I am not able to delete all lines
Dim sw2 As String = IO.File.ReadAllText(textpath)
Dim Lookfor As String = txtuser.Text.Trim()
If sw2.Contains(Lookfor) Then
sw2.remove
Please help
|
|
|
|
|
1) Split string on "[account]"
2) Remove element containing "user = xxx" from split string collection
3) Rejoin remaining elements into a string; using "[account]" + newLine as a delimiter.
(Looks like an ".ini" type of file; you might find a ready made solution on Google for ".ini" files).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you Gerry for the quick response
Please can you be more specific about my situation or could you give me a real example?
Thanks in advance
|
|
|
|
|
|
I can't create a list of string based on search criteria. If a search for "user= test" form textbox I want all the paragraph which belongs to this user to be included in list of string not just one row and then delete all rows which belongs to this user including [account], user,pwd,description,email,address,zip.
I think I don't need to split but join this in a string based in search criteria. (user= test)
Please help me with real code based on the list below
thanks
<b>[account]
user = test
pwd = test
description = test
email = "test@test.com"
address = "balalala"
zip = 235555</b>
|
|
|
|
|
Try something like this:
Shared Iterator Function GroupAccounts(ByVal lines As IEnumerable(Of String)) As IEnumerable(Of IList(Of String))
Dim currentAccount As List(Of String) = Nothing
For Each line As String In lines
If String.IsNullOrWhiteSpace(line) Then Continue For
If String.Equals(line, "[account]", StringComparison.OrdinalIgnoreCase) Then
If currentAccount IsNot Nothing Then Yield currentAccount
currentAccount = New List(Of String)()
End If
If currentAccount IsNot Nothing Then
currentAccount.Add(line)
End If
Next
If currentAccount IsNot Nothing Then
Yield currentAccount
End If
End Function
Shared Iterator Function UngroupAccounts(ByVal groupedAccounts As IEnumerable(Of IEnumerable(Of String))) As IEnumerable(Of String)
Dim started As Boolean = False
For Each account As IEnumerable(Of String) In groupedAccounts
If started Then
Yield String.Empty
Yield String.Empty
End If
For Each line As String In account
Yield line
Next
started = True
Next
End Function
Shared Function RemoveUser(ByVal groupedAccounts As IList(Of IList(Of String)), ByVal userToRemove As String) As Boolean
Dim found As Boolean = False
For index As Integer = groupedAccounts.Count - 1 To 0 Step -1
If groupedAccounts(index).Any(Function (line) String.Equals(line, "user = " & userToRemove, StringComparison.OrdinalIgnoreCase)) Then
groupedAccounts.RemoveAt(index)
Found = true
End If
Next
Return found
End Function Usage:
Dim sourceLines As IEnumerable(Of String) = IO.File.ReadLines(textpath)
Dim groupedAccounts As IList(Of IList(Of String)) = GroupAccounts(sourceLines).ToList()
If RemoveUser(groupedAccounts, txtuser.Text.Trim()) Then
Dim resultLines As IEnumerable(Of String) = UngroupAccounts(groupedAccounts)
IO.File.WriteAllLines(textpath, resultLines)
End If
NB: This will remove any lines from the file which come before the first [account] header, remove any blank lines within an account, and ensure that all accounts are separated by two blank lines.
Now you need to review your password storage:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Richard
But it doesn't seem to work.
It doesn't throw any error.
I executes fine but the user account still remains in text file.
Any other help or way would be appreciated
|
|
|
|
|
Then check the lines in the text file. You probably have a leading or trailing space, or extra spaces between "user", "=", and the username.
The line in the file needs to be exactly equal to:
user<space>=<space><trimmed username to delete>
For example:
user = usertest
If you have other characters on the line, it won't be found, and you'll need to change the search criteria.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|