Sprache: VB
Generiert eine zufällige MAC-Adresse oder HEX Wert.
HEX mit gewünschtem Seperator und in beliebiger länge.
19.11.2007:
Weis zwar nicht, womit ich die 1,8 verdient hab, aber mit Stringbuilder siehts sauberer aus 😉
Public Function GenerateMAC() As String
Dim table As String = "0123456789ABCDEF"
Dim RanMac As New System.Text.StringBuilder
Dim rnd As New System.Random
For i As Integer = 0 To 11
RanMac.Append(table.Substring(rnd.Next(0, table.Length), 1))
Next
Return RanMac.ToString
End Function
Public Function GenerateHEX(ByVal Count As Integer, Optional ByVal Seperator As String = "") As String
If Count < 1 Then Return ""
Dim table As String = "0123456789ABCDEF"
Dim RanHEX As New System.Text.StringBuilder
Dim rnd As New System.Random
For i As Integer = 1 To Count
RanHEX.Append(table.Substring(rnd.Next(0, table.Length), 1))
RanHEX.Append(table.Substring(rnd.Next(0, table.Length), 1))
If i <> Count Then
RanHEX.Append(Seperator)
End If
Next
Return RanHEX.ToString
End Function
Public Function GenerateMAC() As String
Dim table As String = "0123456789ABCDEF"
Dim RanMac As New System.Text.StringBuilder
Dim rnd As New System.Random
For i As Integer = 0 To 11
RanMac.Append(table.Substring(rnd.Next(0, table.Length), 1))
Next
Return RanMac.ToString
End Function
Public Function GenerateHEX(ByVal Count As Integer, Optional ByVal Seperator As String = "") As String
If Count < 1 Then Return ""
Dim table As String = "0123456789ABCDEF"
Dim RanHEX As New System.Text.StringBuilder
Dim rnd As New System.Random
For i As Integer = 1 To Count
RanHEX.Append(table.Substring(rnd.Next(0, table.Length), 1))
RanHEX.Append(table.Substring(rnd.Next(0, table.Length), 1))
If i <> Count Then
RanHEX.Append(Seperator)
End If
Next
Return RanHEX.ToString
End Function
Alte URL:
/snippet/mac-und-hex-generieren/671
Why is it votoed so bad? With a little Modification it´s working really great
Das .ToString bei den beiden Returns brauchst du nicht 😉
Geht auch einfach so:
[b]…
Return RenHEX
…[/b]