This commit is contained in:
ms
2021-07-01 08:39:14 +02:00
parent 1870307007
commit 67f2a10607
15 changed files with 247 additions and 52 deletions

View File

@@ -645,30 +645,114 @@ Public Class Main
End Function
Private Sub CmdTest_Click(sender As Object, e As EventArgs) Handles CmdTest.Click
DHCP.DHCP1("192.168.0.98")
End Sub
Private Sub CMdTest2_Click(sender As Object, e As EventArgs) Handles CMdTest2.Click
Dim testuser As New cDomUser
testuser.getDomUser("mit_email", "ms@verag.ag")
Dim frm As New frmLeer
frm.Text = "Benutzerverwaltung"
Dim usrcntrl As New uscntr_DomUser
usrcntrl.DomUser = testuser
usrcntrl.Dock = DockStyle.Fill : frm.PanMain.Controls.Add(usrcntrl)
frm.Size = usrcntrl.Size
frm.Show()
AddHandler frm.FormClosing, Function()
End Function
DeleteGastWLANUser("ABABAB")
End Sub
Private Sub btnTest3_Click(sender As Object, e As EventArgs) Handles btnTest3.Click
RestartServices("TS12.verag.ost.dmn", "Druckerwarteschlange")
Dim i As Integer = 0
Dim c As String
' For meh As Integer = 0 To 1
Dim a, b As String
a = UsernamePasswordGenerator("u")
b = UsernamePasswordGenerator("p")
c &= a & " - " & b & vbCrLf
AddGastWLANUser(a, b)
'Next
WriteToFile(Application.StartupPath & "\WLAN.txt", c)
'MsgBox(a & vbCrLf & b)
End Sub
Public Function UsernamePasswordGenerator(x As String, Optional ByVal Zeichenanzahl As Integer = 6) As String ' wenn u dann Username, sonst Password
Dim str As String
Dim up As String
If x = "u" Then
str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Else
str = "0123456789"
End If
Dim r As New Random
For i As Integer = 0 To Zeichenanzahl - 1
up &= str(r.Next(0, str.Length)).ToString
Next
Return up
'MsgBox(up)
End Function
Private Function AddGastWLANUser(Username As String, Optional ByVal Password As String = "verag1", Optional ByVal Zugangsdaten As String = "WLANAdmin@192.168.0.97 -pw 6a0D5Ys93uugLi3uVciV", Optional ByVal AblaufZeit As Integer = 2)
If Not File.Exists(Application.StartupPath & "\AddWLANUser.bat") Then File.Create(Application.StartupPath & "\AddWLANUser.bat")
Dim AddWLANUser As String = Application.StartupPath & "\AddWLANUser.bat"
Dim exptime As String = Date.Now.AddHours(AblaufZeit).ToString("yyyy-MM-dd HH:mm")
Dim battext As String = ""
battext = "(
echo configure terminal
echo dynamic-guest username " & Username & "
echo password " & Password & "
echo expire-time " & exptime & "
echo group Fahrer_Gruppe
echo exit
echo exit
echo exit
) | plink -ssh " & Zugangsdaten & "
exit"
WriteToFile(AddWLANUser, battext)
Threading.Thread.Sleep(1500)
Dim Add As New Process
Add.StartInfo.FileName = Application.StartupPath & "\RunNHide.exe"
Add.StartInfo.Arguments = AddWLANUser
Add.Start()
End Function
Private Function DeleteGastWLANUser(Username As String, Optional ByVal Zugangsdaten As String = "WLANAdmin@192.168.0.97 -pw 6a0D5Ys93uugLi3uVciV")
If Not File.Exists(Application.StartupPath & "\DELWLANUser.bat") Then File.Create(Application.StartupPath & "\DELWLANUser.bat")
Dim DELWLANUser As String = Application.StartupPath & "\DELWLANUser.bat"
Dim battext As String = ""
battext = "(
echo configure terminal
echo no dynamic-guest " & Username & "
echo exit
echo exit
echo exit
) | plink -ssh " & Zugangsdaten & "
exit"
WriteToFile(DELWLANUser, battext)
Threading.Thread.Sleep(1500)
Dim del As New Process
del.StartInfo.FileName = Application.StartupPath & "\RunNHide.exe"
del.StartInfo.Arguments = DELWLANUser
del.Start()
'Process.Start(Application.StartupPath & "\RunNHide.exe " & DELWLANUser)
End Function
Public Shared Function WriteToFile(filepath As String, texttowrite As String)
Try
Dim objWriter As New System.IO.StreamWriter(filepath)
objWriter.Write(texttowrite)
objWriter.Close()
Catch ex As Exception
MsgBox(filepath & vbCrLf & " konnte nicht geschrieben werden." & vbCrLf & ex.Message)
End Try
End Function
Public Sub RestartServices(Servername As String, Dienst As String)
'Dim Servername As String = "TS12.verag.ost.dmn"
@@ -715,21 +799,30 @@ Public Class Main
Public Function GetDHCPClients(Netzwerk As String, DHCPServer As String, Fill As Boolean, ByRef ds As DataSet)
Dim NWShort As String
Dim DHCPClientList = DHCP.DHCP1(DHCPServer)
'Dim NWShort As String
Dim DHCPClientIP As String
Dim dhcpclients() As DHCP.DHCP_CLIENT_INFO
'Dim dhcpclients() As DHCP.DHCP_CLIENT_INFO
LblDebugInfo.Text &= ""
Dim a As UInteger = DHCP.StringIPAddressToUInt32(Netzwerk)
Dim b As UInteger = DHCP.StringIPAddressToUInt32("255.255.255.255")
DHCP.ListSubnetClients(DHCPServer, Netzwerk, dhcpclients)
DHCP.StringNWAdressToNWAdressSHORT(Netzwerk, NWShort)
'Dim a As UInteger = DHCP.StringIPAddressToUInt32(Netzwerk)
'Dim b As UInteger = DHCP.StringIPAddressToUInt32("255.255.255.255")
'DHCP.ListSubnetClients(DHCPServer, Netzwerk, dhcpclients)
'DHCP.StringNWAdressToNWAdressSHORT(Netzwerk, NWShort)
'Dim test As String
'For Each client In DHCPClientList
' test &= client.name & vbCrLf
'Next
Try
For i = 0 To DHCP.Client_Array.NumElements - 1
For Each dhcpclient In DHCPClientList 'DHCP.Client_Array.NumElements - 1
DHCPClientIP = NWShort & (b - ((dhcpclients(i).ClientIpAddress * -1) + a - 1)).ToString
DHCPClientIP = dhcpclient.IpAddress.ToString 'NWShort & (b - ((dhcpclient.IpAddress * -1) + a - 1)).ToString
''----------------------------------------Fill True: Wenn DHCP Clients bereits im DS enthalten sind werden diese Hosts geändert.
' If Fill = True Then
@@ -737,7 +830,7 @@ Public Class Main
HostRow = ds.Tables(0).Select("IPAdresse = '" & DHCPClientIP & "'")
' MsgBox(DHCPClientIP & HostRow.Length)
If HostRow.Length > 0 Then
HostRow(0)("FQDN") = "*" & dhcpclients(i).ClientName
HostRow(0)("FQDN") = "*" & dhcpclient.Name
HostRow(0)("QINFO") = "DHCP Client"
@@ -752,10 +845,10 @@ Public Class Main
Dim newrow As DataRow = ds.Tables(0).NewRow()
newrow("IPAdresse") = DHCPClientIP
newrow("FQDN") = "*" & dhcpclients(i).ClientName
newrow("FQDN") = "*" & dhcpclient.Name
newrow("QINFO") = "DHCP Client"
newrow("DHCP") = "1"
newrow("Host") = (b - ((dhcpclients(i).ClientIpAddress * -1) + a - 1)).ToString
newrow("Host") = Class1.IP2Host(dhcpclient.ipaddress.ToString) '(b - ((dhcpclient.IPAddress * -1) + a - 1)).ToString
ds.Tables(0).Rows.Add(newrow)
'End If