Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Regarding telnet

Regarding telnet

Scheduled Pinned Locked Moved C#
csharphelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    praveenkumar palla
    wrote on last edited by
    #1

    how to connect to telnet and execute the commands using c#.net Please help me on this Praveenkumar Palla

    E 1 Reply Last reply
    0
    • P praveenkumar palla

      how to connect to telnet and execute the commands using c#.net Please help me on this Praveenkumar Palla

      E Offline
      E Offline
      Ermak86
      wrote on last edited by
      #2

      use TcpClient class. to connect use its constructor TcpClient(String hostname, int Port) to write a command: byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(command.Replace("\0xFF","\0xFF\0xFF")); TcpClient.GetStream().Write(buf, 0, buf.Length); to read: byte[] bytes = new byte[tcpClient.ReceiveBufferSize]; TcpClient.GetStream().Read(bytes, 0, (int)tcpClient.ReceiveBufferSize); String s = Encoding.ASCII.GetString(bytes); Choose encoding which you need in read and write instead of TcpClient use your TcpClient instance name Pawel

      P 1 Reply Last reply
      0
      • E Ermak86

        use TcpClient class. to connect use its constructor TcpClient(String hostname, int Port) to write a command: byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(command.Replace("\0xFF","\0xFF\0xFF")); TcpClient.GetStream().Write(buf, 0, buf.Length); to read: byte[] bytes = new byte[tcpClient.ReceiveBufferSize]; TcpClient.GetStream().Read(bytes, 0, (int)tcpClient.ReceiveBufferSize); String s = Encoding.ASCII.GetString(bytes); Choose encoding which you need in read and write instead of TcpClient use your TcpClient instance name Pawel

        P Offline
        P Offline
        praveenkumar palla
        wrote on last edited by
        #3

        Thanks for the reply Pawel But One issue, First I connected to remote system(using IP,port) using TcpClient constructor. then I red command (why because when I connected to that system it is prompting for the login and then password) It returns the string "????????\0??\0Microsoft (R) Windows (TM) Version 5.00 (Build 2195)\r\nWelcome to Microsoft Telnet Service \r\nTelnet Server Build 5.00.99206.1\n\rlogin: \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" then I wrote a command string command="administrator";////////"administrator" that system login name byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(command.Replace("\0xFF","\0xFF\0xFF")); TcpClient.GetStream().Write(buf, 0, buf.Length); Again I red command(actually it should return "Password:" ) but it returns "administrator?\0Microsoft (R) Windows (TM) Version 5.00 (Build 2195)\r\nWelcome to Microsoft Telnet Service \r\nTelnet Server Build 5.00.99206.1\n\rlogin: \0\0\0\0\0\0\0\0\0\0\0\0\0\0\" So not connected.....Please help me on this Actually my application needs backend execution of commands at cmd.exe of remote systems (using IP) and should return command result. Please help me on this

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups