Question c++ to vb.net

just369

Member
Joined
May 12, 2010
Messages
17
Programming Experience
Beginner
how can i transcribe this to vb.net



VB.NET:
 public string WriteNReadBuffer(byte [] TelnetNegotiation, NetworkStream stream)
    {
            stream.Write(TelnetNegotiation, 0, TelnetNegotiation.Length);
            Byte[] data = new Byte[256];
            Int32 bytes = stream.Read(data, 0, data.Length);
            string returnval;
            returnval = BitConverter.ToString(data, 0, bytes) + "\r\n";
            //textBox2.AppendText(BitConverter.ToString(data, 0, bytes) + "\r\n");
            return returnval;
    }
        public void Wait4Prompt(string PromptSearch, NetworkStream stream)
        {
            Byte[] data6 = new Byte[256];
            Int32 bytes6 = stream.Read(data6, 0, data6.Length);
            string bufferstring = (BitConverter.ToString(data6, 0, bytes6) + "\r\n");

            //Wait for particular prompt - Look for hex value for login: or password:
            while ((bufferstring.Contains(PromptSearch) != true))
            {
                Byte[] data7 = new Byte[256];
                Int32 bytes7 = stream.Read(data7, 0, data7.Length);
                bufferstring = (BitConverter.ToString(data7, 0, bytes7) + "\r\n");
            }
        }


        private void button3_Click(object sender, EventArgs e)
        {
            string server = "10.x.x.x";
            Int32 port = 23;
            TcpClient client = new TcpClient(server, port);
            NetworkStream stream = client.GetStream();

//          WONT terminal type, window size, x display location, new environment option, environment option
            textBox2.AppendText(WriteNReadBuffer(new byte[] { 255, 252, 24, 255, 252, 31, 255, 252, 35, 255, 252, 39, 255, 252, 36 }, stream));

//          DO echo, suppress go ahead
            textBox2.AppendText(WriteNReadBuffer(new byte[] { 255, 253, 01, 255, 253, 03 }, stream));

            //Wait for login prompt - Look for hex value for login:
            Wait4Prompt("6C-6F-67-69-6E-3A-20\r\n",stream);

//          Send user1
            textBox2.AppendText(WriteNReadBuffer(new byte[] { 117, 115, 101, 114, 49, 13, 10 }, stream));

            //Wait for password prompt - Look for hex value for password:
            Wait4Prompt("50-61-73-73-77-6F-72-64-3A-20", stream);                    
//          Send pass1
            textBox2.AppendText(WriteNReadBuffer(new byte[] { 112, 97, 115, 115, 49, 13, 10 }, stream));
//          Send pass1
            textBox2.AppendText(WriteNReadBuffer(new byte[] { 112, 97, 115, 115, 49, 13, 10 }, stream));

//         Wait for last login message - Look for hex value for last login:
            Wait4Prompt("4C-61-73-74-20-6C-6F-67-69-6E-3A-20", stream);
//          Send ./sync
            textBox2.AppendText(WriteNReadBuffer(new byte[] { 46, 47, 115, 121, 110, 99, 13, 10 }, stream));
            
            stream.Close();
            client.Close(); 


        }
 
VB.NET:
Public Function WriteNReadBuffer(ByVal TelnetNegotiation() As Byte, ByVal stream As NetworkStream) As String
		stream.Write(TelnetNegotiation, 0, TelnetNegotiation.Length)
		Dim data(256) As Byte
		Dim bytes As Int32 = stream.Read(data, 0, data.Length)
		Dim returnval As String = BitConverter.ToString(data, 0, bytes) & vbCrLf
		' textBox2.AppendText(BitConverter.ToString(data, 0, bytes) & vbCrLf)
		Return returnval
	End Function
	Public Sub Wait4Prompt(ByVal PromptSearch As String, ByVal stream As NetworkStream)
		Dim data6(256) As Byte
		Dim bytes6 As Int32 = stream.Read(data6, 0, data6.Length)
		Dim bufferstring As String = BitConverter.ToString(data6, 0, bytes6) & vbCrLf

		' Wait for particular prompt - Look for hex value for login: or password:
		While (bufferstring.Contains(PromptSearch) <> True)
			Dim data7(257) As Byte
			Dim bytes7 As Int32 = stream.Read(data7, 0, data7.Length)
			bufferstring = BitConverter.ToString(data7, 0, bytes7) & vbCrLf
		End While
	End Sub
	Public Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button3.Click
		Dim server As String = "10.x.x.x"
		Dim port As Int32 = 23
		Dim client As New TcpClient(server, port)
		Dim stream As NetworkStream = client.GetStream()

		'          WONT terminal type, window size, x display location, new environment option, environment option
		Dim sendBytes() As Byte
		sendBytes = New Byte() {255, 252, 24, 255, 252, 31, 255, 252, 35, 255, 252, 39, 255, 252, 36}
		textBox2.AppendText(WriteNReadBuffer(sendBytes, stream))

		'          DO echo, suppress go ahead
		sendBytes = New Byte() {255, 253, 1, 255, 253, 3}
		textBox2.AppendText(WriteNReadBuffer(sendBytes, stream))

		'Wait for login prompt - Look for hex value for login:
		Wait4Prompt("6C-6F-67-69-6E-3A-20\r\n", stream)

		'          Send user1
		sendBytes = New Byte() {117, 115, 101, 114, 49, 13, 10}
		textBox2.AppendText(WriteNReadBuffer(sendBytes, stream))

		'Wait for password prompt - Look for hex value for password:
		Wait4Prompt("50-61-73-73-77-6F-72-64-3A-20", stream)
		'          Send pass1
		sendBytes = New Byte() {112, 97, 115, 115, 49, 13, 10}
		textBox2.AppendText(WriteNReadBuffer(sendBytes, stream))
		'          Send pass1
		sendBytes = New Byte() {112, 97, 115, 115, 49, 13, 10}
		textBox2.AppendText(WriteNReadBuffer(sendBytes, stream))

		'         Wait for last login message - Look for hex value for last login:
		Wait4Prompt("4C-61-73-74-20-6C-6F-67-69-6E-3A-20", stream)
		'          Send ./sync
		sendBytes = New Byte() {46, 47, 115, 121, 110, 99, 13, 10}
		textBox2.AppendText(WriteNReadBuffer(sendBytes, stream))

		stream.Close()
		client.Close()
	End Sub
 
Back
Top