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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
| Imports System.IO
Imports System.Net.Sockets
Imports System.DirectoryServices
Imports System.Net
Public Class Form1
Dim listerner As New TcpListener(23)
Dim client As TcpClient
Dim message As String = ""
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Text = TextBox1.Text + " says " + RichTextBox1.Text
RichTextBox1.Text = MessageTransposition(RichTextBox1.Text, False)
Timer2.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If listerner.Pending = True Then
message = ""
client = listerner.AcceptTcpClient
Dim reader As New StreamReader(client.GetStream())
While reader.Peek > -1
message = message + Convert.ToChar(reader.Read()).ToString
End While
Me.Focus()
message = MessageTransposition(message, False)
RichTextBox2.Text = RichTextBox2.Text + message + vbCrLf
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim childEntry As DirectoryEntry
Dim ParentEntry As New DirectoryEntry()
Try
ParentEntry.Path = "WinNT:"
For Each childEntry In ParentEntry.Children
Dim newNode As New TreeNode(childEntry.Name)
Select Case childEntry.SchemaClassName
Case "Domain"
Dim ParentDomain As New TreeNode(childEntry.Name)
TreeView1.Nodes.AddRange(New TreeNode() {ParentDomain})
Dim SubChildEntry As DirectoryEntry
Dim SubParentEntry As New DirectoryEntry()
SubParentEntry.Path = "WinNT://" & childEntry.Name
For Each SubChildEntry In SubParentEntry.Children
Dim newNode1 As New TreeNode(SubChildEntry.Name)
Select Case SubChildEntry.SchemaClassName
Case "Computer"
ParentDomain.Nodes.Add(newNode1)
End Select
Next
End Select
Next
Catch Excep As Exception
MsgBox("Error While Reading Directories")
Finally
ParentEntry = Nothing
End Try
listerner.Start()
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
listerner.Stop()
End Sub
Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
TextBox2.Text = GetIPAddress(TreeView1.SelectedNode.Text)
End Sub
Function GetIPAddress(ByVal CompName As String) As String
Dim oAddr As System.Net.IPAddress
Dim sAddr As String
Try
With System.Net.Dns.GetHostEntry(CompName)
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
sAddr = oAddr.ToString
End With
GetIPAddress = sAddr
Catch Excep As Exception
MsgBox(Excep.Message, MsgBoxStyle.OKOnly, "Lan Messenger")
Finally
End Try
End Function
Private Sub RichTextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles RichTextBox1.KeyDown
If e.KeyCode = Keys.Insert Then
RichTextBox1.Text = TextBox1.Text + " says " + RichTextBox1.Text
RichTextBox1.Text = MessageTransposition(RichTextBox1.Text, False)
Timer2.Start()
End If
End Sub
Dim ChkXOR As New CheckBox
Private Function MessageTransposition(ByVal StrDataIn As String, ByVal ED As Boolean) As String
'>>> if neded xor, use this code
Dim XORCode As Integer
XORCode = 213
Dim rowind As Integer 'index row
Dim colind As Integer 'index column
rowind = 1
colind = 1
'>>> create the array
Dim DataArray(rowind, colind) As String
Dim i, j As Integer
Dim r, c As Integer
Dim output As String
output = ""
i = 1
'>>> loop to total length
While i <= StrDataIn.Length
'>>> clear the array
For r = 0 To rowind
For c = 0 To colind
DataArray(r, c) = Chr(1)
Next
Next
'>>> check the loop last postion
Dim LastPos As Integer
If i + (rowind * colind) - 1 <= StrDataIn.Length Then
LastPos = i + (rowind * colind) - 1
Else
LastPos = StrDataIn.Length
End If
'>>> store strdata in into array character by character
'>>> initial the array indexer
r = 0
c = 0
For j = i To LastPos
ChkXOR.Checked = True
'>>> check if need to XOR the character
If ChkXOR.Checked = True Then
Dim TempChar As String
TempChar = Mid(StrDataIn, j, 1)
DataArray(r, c) = Chr(Asc(TempChar) Xor XORCode)
Else
DataArray(r, c) = Mid(StrDataIn, j, 1)
End If
c = c + 1
'>>> reset the array indexer
If r > rowind - 1 Then
r = 0
c = 0
End If
If c > colind - 1 Then
c = 0
r = r + 1
End If
Next
'>>> add array value to string coulumn nad row wise
If ED = True Then
For c = 0 To colind - 1
For r = 0 To rowind - 1
output = output & DataArray(r, c)
Next
Next
Else
'>>> decrypt logics
Dim StrTemp As String
StrTemp = ""
Dim p, p1 As Integer
p = 1
p1 = 1
For r = 0 To rowind - 1
For c = 0 To colind - 1
StrTemp = StrTemp & DataArray(r, c)
Next
Next
While p <= StrTemp.Length
'>>> replace array filling character
'>>> check if it is xor
ChkXOR.Checked = True
If ChkXOR.Checked = True Then
output = output & Replace(Mid(StrTemp, p1, 1), Chr(Asc(Chr(1)) Xor XORCode), "")
Else
output = output & Replace(Mid(StrTemp, p1, 1), Chr(1), "")
End If
p = p + 1
'>>> increment position by row
p1 = p1 + rowind
If p1 > StrTemp.Length Then
p1 = p1 - StrTemp.Length + 1
End If
End While
End If
i = i + rowind * colind
End While
MessageTransposition = output
End Function
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Timer2.Stop()
client = New TcpClient(TextBox2.Text, 23)
Dim writer As New StreamWriter(client.GetStream())
writer.Write(RichTextBox1.Text)
writer.Flush()
RichTextBox1.Text = ""
End Sub
End Class |
Partager