GithubHelp home page GithubHelp logo

telnet's Introduction

telnet's People

Contributors

garyburd avatar jroes avatar michalderkacz avatar siff-duke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telnet's Issues

How to disable echo?

The code SetEcho(false) doesn't work in your code, but when I use telnet command in Linux shell, the echo mode is disabled.

SkipUntil leads to "index out of range" error in bufio

We sometimes use SkipUntil with a single string argument in our code, for example teln.SkipUntil("querymvisvc"), and this sometimes leads to the error stack below:

panic: runtime error: index out of range

goroutine 853 [running]:
bufio.(*Reader).ReadByte(0xc0024d57a0, 0x54f837, 0x0, 0x0)
	/usr/local/go/src/bufio/bufio.go:251 +0xcb
github.com/ziutek/telnet.(*Conn).tryReadByte(0xc00175ccc0, 0x560037, 0x0, 0x0)
	/go/pkg/mod/github.com/ziutek/[email protected]/conn.go:230 +0x33
github.com/ziutek/telnet.(*Conn).ReadByte(0xc00175ccc0, 0x37, 0x0, 0x0)
	/go/pkg/mod/github.com/ziutek/[email protected]/conn.go:261 +0x38
github.com/ziutek/telnet.(*Conn).readUntil(0xc00175ccc0, 0x5aec00, 0xc006c55130, 0x1, 0x1, 0xc002245538, 0x40bff8, 0x10, 0x570320, 0x1, ...)
	/go/pkg/mod/github.com/ziutek/[email protected]/conn.go:364 +0x12e
github.com/ziutek/telnet.(*Conn).SkipUntil(0xc00175ccc0, 0xc006c55130, 0x1, 0x1, 0x3, 0x3)
	/go/pkg/mod/github.com/ziutek/[email protected]/conn.go:405 +0x51
bitbucket.org/team/teamrepo/processor.queryDMC(0x5e2440, 0xc00175ccc0, 0xc003646223, 0x2, 0xc0002bf640, 0xe, 0xc0002bf638, 0x4, 0xc0002bf650, 0x6, ...)

How to remove control characters on the output of telnet?

Hi, Ziutek. Maybe it's not proper to ask this question here, but it really confused me for several days.
I want to remove all control characters in the telnet output because there are too many special characters over there. For example, the telnet output is:

ae23        Enabled     Down    Disabled      Auto    Auto                                                    ^M^@^M
ae24        Enabled     Down    Disabled      Auto    Auto                                                    ^M^@^M
^[[J^M^@ --More-- (END) ^[[J^M^@ --More-- (END) ^[[J^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[J^[[J^[[J^M^@test.Int> exit

There are some extra characters including non-printable and printable like ^[, ^H, ^M, [J, --More-- (END) and so on. But this output is normal when printing on the screen:

ae23        Enabled     Down    Disabled      Auto    Auto
ae24        Enabled     Down    Disabled      Auto    Auto
test.Int> exit

All the control character are not shown. I know there is a way that uses col -b bash command to remove them. But it's not an effective way because telnet is an interactive way. Using os.exec to filter control characters for every command is not good.
So do you have any idea to remove all the control characters on the telnet output?

Two questions about telnet option

Hi, Dear Ziutek,

Sorry to bother you again. I have two questions about the telnet option recently. I used your library to telnet different switch and router. Some of them are OK, while some are not.

  1. The "Password:" string didn't show
    After login into the switch using telnet, the Username: characters show normally. Some switches don't show the password: characters after typing the username. Actually, no response occurred whatever I type.
    In my experiments, some switches can display the password: character but some aren't. I can't find any help in the google results and (rfc854)[https://tools.ietf.org/html/rfc854]. Do you know it's telnet option problem or switch configuration problem?
    Supplement: the password: string can all be displayed normally when using (Linux telnet client)[https://linux.die.net/man/1/telnet].

  2. "echo option" negotiate loop
    I didn't modify your code so that for every IAC WILL ECHO/255 251 1 reply IAC DO ECHO/255 253 2; for every IAC WON'T ECHO/255 252 1 reply IAC DON'T ECHO/255 254 1. This strategy should work OK according to the (rfc854)[https://tools.ietf.org/html/rfc854]. But some switches go into dead loop, here comes the print from debug:

received cmd: 251 1
received cmd: 251 1
received cmd: 251 1
received cmd: 251 3
received cmd: 253 24
received cmd: 253 31
received cmd: 252 1
received cmd: 251 1
received cmd: 254 24
received cmd: 254 31
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
received cmd: 251 1
received cmd: 252 1
.... // print omit: "255 251 1" and "255 252 1" display respectively

I don't know whether it's problem of switch telnet version. What I want is accept any echo configuration. Here comes the description of option response in rfc854:

If a party receives what appears to be a request to enter some mode it is already in, the request should not be acknowledged. This non-response is essential to prevent endless loops in the negotiation. It is required that a response be sent to requests for a change of mode -- even if the mode is not changed.

In my understanding, no response means enable. So I modify your code in func (c *Conn) cmd(cmd byte) that doesn't reply any do and don't when receive will and won't:

	switch o {
	case optEcho:
		// Accept any echo configuration.
		switch cmd {
		case cmdDo:
			if !c.cliEcho {
				c.cliEcho = true
				err = c.will(o)
			}
		case cmdDont:
			if c.cliEcho {
				c.cliEcho = false
				err = c.wont(o)
			}
		case cmdWill:
			// err = c.do(o) // erase
		case cmdWont:
			// err = c.dont(o) // erase
		}

It looks like the switch enable echo option which is what I want. Do you think it's a right way to erase these two line code to enable echo option?

Stuck on reading

When I tried to use this client to connect to some mud servers, I found that sometimes it doesn't print all the text. After some digging, I found that the program got stuck on conn.Read when it's fed with a big buffer.

After more digging, I found out that the c.r.Buffered() returns more than 0, so it get stuck at c.ReadByte() in the next iteration.
https://github.com/ziutek/telnet/blob/master/conn.go#L306

Also, I'm not sure if it's related, but usually it gets stuck in the middle on a line.

I'm not familiar with telnet or your client enough to solve this. Could you take a look?

Below is a snippet that can show the problem. You can run it multiple times to see how the problem is like.

func main() {
	conn, err := telnet.Dial("tcp", "bat.org:23")
	if err != nil {
		log.Fatal(err)
	}

	for {
		data := make([]byte, 512) // if I change the buffer size to 1, it doesn't hang
		n, err := conn.Read(data)
		if n > 0 {
			fmt.Print(string(data))
		}

		if err != nil {
			log.Fatal(err)
		}
	}
}

Missing license

I'd like to use this library, but without a license I cannot in good conscience include it in my code.

Read until blank line

Hello,

I am using your library as part of connecting to systems to run a command, read the output, and then run another command. The system in question doesn't have a character as its prompt (e.g. no $ or >) and as such, I can't figure out what I should be passing to the ReadUntil() function. I was using a carriage return string "\r" but this isn't always effective as the output can be multiple lines.

Have you accounted for this use case?

Many thanks

EDIT: Perhaps there is some way to define a regex pattern that is matched?

i/o time out

Hello,
I am using the main.go example to connect to
telnet.reversebeacon.net:7000
and I receive a time out.

I can connect without any issues with other clients.
Any help?

Go version: 1.9.4
OS: Windows 7 Enterprise 64-bits.
No build errors.
Error recevied from the telnet server:
2018/02/12 18:30:33 Error: read tcp 192.168.1.5:54852->198.137.202.75:7000: i/o
timeout

Hope you can help me.
Thanks.

Cisco ASA 5505 connection issues

Hi, trying to connect to a Cisco ASA 5505, I found that the option subcommands SB and SE were not being catched, so I have added this codes cmdSB and cmdSE to line 111 of conn.go. That allowed me to connect and to send commands succesfully.

Regards,

Lucas

Fortigate FortiOS connection issues

I am having some trouble with logging into Fortigate via telnet. Connecting and initial use works fine to Fortigate. This is a virtual instance on KVM (FortiGate-VM64-KVM). More specifically, Version: FortiGate-VM64-KVM v5.6.1,build1484,170727.

For reference: Example telnet connection (with regular telnet command):

Escape character is '^]'.

hostname login: admin
Password: **********
Welcome !

hostname #

when connecting with the telnet library, I can write "admin" and then read until "sword: "
Then writing the password "mypassword" followed by a newline, it echoes a "" for each letter.
Reading back, I get the "
*********" however nothing more comes after that and the connection hangs.
It feels as if the password is not finished to enter and nothing more comes back after reading.
The password insertion is do is handled in the same way as the username insertion which works, so it is somewhat surprising.

Is it possible that the fortigate is using some option/setting that is not supported and is causing this behavior? Any ideas would be appreciated.

Thanks,
Gus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.