Re: [go-nuts] Re: How to implement this in golang?

2021-07-12 Thread LetGo
I posted the wrong code I tried also something simple like that: cmd := exec.Command(binPath, "-i") //bin/sh -i cmd.Stdin = conn stdout := new(bytes.Buffer) cmd.Stdout = io.Write(stdout) conn.Write(stdout.Bytes()) cmd.Stderr = conn cmd.Run() Still no output of the commands

Re: [go-nuts] Re: How to implement this in golang?

2021-07-11 Thread LetGo
I tried also something simple like that: cmd := exec.Command(binPath, "-i") //bin/sh -i cmd.Stdin = conn var stdout bytes.Buffer cmd.Stdout = &stdout conn.Write(stdout.Bytes()) cmd.Stderr = conn cmd.Run() Still no output of the commands I enter Il giorno domenica 11 luglio 2

Re: [go-nuts] Re: How to implement this in golang?

2021-07-11 Thread LetGo
AH sorry! It was a really tough day and I tried to code in the worst situation ever, I was really tired that I did not even noticed how stupid and newbie was that, sorry! PLEASE just ignore my last comment... ahah Im REALLY embarrassed After a break of 2 days, I went back on my code, and

Re: [go-nuts] Re: How to implement this in golang?

2021-07-08 Thread Brian Candler
Complete code on play.golang.org is much easier to understand. At the moment I don't think your code will do anything useful. For example buf := new(bytes.Buffer) ... bizz := buf.Bytes() will always set bizz to an empty slice; since you never modify

Re: [go-nuts] Re: How to implement this in golang?

2021-07-08 Thread Levieux Michel
This error is pretty straightforward 😅 You declared a variable (i.e. kk) that is not used after its declaration. Note that assignment is not use. I have to admit I don't know what this variable is supposed to be used for but that does not matter, if you don't know, maybe just try dropping it and se

Re: [go-nuts] Re: How to implement this in golang?

2021-07-08 Thread Kurtis Rader
The error is self explanatory. You define variable "kk" but never use it. If you don't care about the return value of io.Writer() simply omit the assignment; just call the function. Or explicitly assign to the special "_" placeholder var to show that you know the function returns a value and you ar

Re: [go-nuts] Re: How to implement this in golang?

2021-07-08 Thread LetGo
I thought that after getting the bytes, chunk the data, I need to have the io.writer back before send the chunked data So far I came up with this: ... cmd.Stdin = conn buf := new(bytes.Buffer) cmd.Stdout = buf bizz := buf.Bytes() var i int

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread Levieux Michel
You cannot *per se* convert an interface or a struct to a builtin like []byte You might wanna have a look at the Bytes method of *bytes.Buffer, which returns the internal buffer of the type as a slice of bytes. Normally that would have been a good exerci

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
Thanks for your answer!(: You are right, but I just wanted to have this one little tool in Go and I have never thought that could be that hard... ahahah By the way, it works as you said, it fixed the error! ( obviously.. ) the only thing left is to convert type *bytes.Buffer to []byte * I think

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread Levieux Michel
[Sorry forgot to hit "Reply all"] Are you trying to cast cmd.Stdout here? What you can do is: buf := new(bytes.Buffer) cmd.Stdout = buf // buf is an io.Writer so this is fine but I don't get the point of the data := foo? Maybe, before trying to convert a whole complex program in Python to a whol

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
One of these is this: ... buf := new(bytes.Buffer) foo := buf(cmd.Stdout) // this line is 87 data := foo var i int ... pkg/conn.go:87:20: cannot call non-function buf (type *bytes.Buffer) Il giorno mercoledì 7 luglio 2021 alle 12:10:03 UTC+2 LetGo ha scritto

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
I tried also both of them, but I got stuck into a loop of errors again.. probably I coded in the wrong way Il giorno mercoledì 7 luglio 2021 alle 11:50:51 UTC+2 Brian Candler ha scritto: > It makes no sense to convert an io.Writer to a string. > > io.Writer is an interface: any type which has a

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread Brian Candler
It makes no sense to convert an io.Writer to a string. io.Writer is an interface: any type which has a Write() method. So you can pass a string *to* a writer, to get it written somewhere, by calling the Write() method. In general, you can't get a string *from* a writer. If you google "go io.

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
Thanks for your answer!(: You are right, sorry! This is the code: https://play.golang.org/p/zEZ2HIUNffs About the lines, wow! Yes, you got them! ahah About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/ strings, but.. I have then entered into a loop of errors... Il giorno mar

Re: [go-nuts] Re: How to implement this in golang?

2021-07-06 Thread Brian Candler
You haven't shown which lines 75, 76 and 83 correspond to. It's easier if you put the whole code on play.golang.org, and we'll be able to point to the error. But I'm guessing it's this: data := cmd.Stdout ... n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data << line 75?

Re: [go-nuts] Re: How to implement this in golang?

2021-07-06 Thread LetGo
I think I made some progress I think. Is it right what I'm doing ? cmd.Stdin = conn // cmd.Stdout = conn // data := []byte(cmd.Stdout) data := cmd.Stdout var i int for { n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data d

Re: [go-nuts] Re: How to implement this in golang?

2021-06-29 Thread LetGo
Thank you guys for all your answers and suggestions! I really appreciate! Sorry about the screenshots, it was the only way to make the packets "human readable" How could you code that kind of implementation based on your knowledge and skill? I have noone of these in golang ahah as I said, im too

Re: [go-nuts] Re: How to implement this in golang?

2021-06-29 Thread Jesper Louis Andersen
On Tue, Jun 29, 2021 at 5:24 PM LetGo wrote: > Thanks for the answer! (: > In python it was straightforward to implement and it works like a charm. > It sends small packets with delay between each other without even care if > it is UDP or TCP: > > Beware! This is an assumption that will break at

Re: [go-nuts] Re: How to implement this in golang?

2021-06-29 Thread Marvin Renich
[Please do not send images of text; copy and paste as text into the message or into text attachments.] * LetGo [210629 11:25]: > Thanks for the answer! (: > In python it was straightforward to implement and it works like a charm. It > sends small packets with delay between each other without eve

Re: [go-nuts] Re: How to implement this in golang?

2021-06-29 Thread Robert Engels
With Go you use a Go routine per connection and then you can read in chunks and delay in an imperative style. No need for generators or async. > On Jun 29, 2021, at 10:25 AM, LetGo wrote: > > Thanks for the answer! (: > In python it was straightforward to implement and it works like a charm.

[go-nuts] Re: How to implement this in golang?

2021-06-29 Thread LetGo
Thanks for the answer! (: In python it was straightforward to implement and it works like a charm. It sends small packets with delay between each other without even care if it is UDP or TCP: [image: prooff.png] [image: proof2.png] The connection ( if UDP/ TCP ) is handled independently, the s

[go-nuts] Re: How to implement this in golang?

2021-06-29 Thread Brian Candler
What sort of socket - TCP or UDP? TCP is an infinite stream, and there is no reliable way to divide it into "chunks" (except possibly using the URG pointer, which is very rarely used). There is no guarantee that waiting 1.6 seconds between sends will actually send in separate segments being s

[go-nuts] Re: How to implement this in golang?

2021-06-29 Thread LetGo
I forgot this: // Manage connection for different behavior func handleConn(conn net.Conn, binPath string) { msg := "Status?\n" if binPath != "" { // Execute command and send Standard I/O net.Conn cmd := exec.Command(binPath) cmd.Stdin = conn cmd.Stdout = conn cmd.Stderr = conn

[go-nuts] Re: How to implement this In golang

2016-09-20 Thread gary . willoughby
Try this tutorial: http://go-database-sql.org/ On Monday, 19 September 2016 16:48:54 UTC+1, kumargv wrote: > > cursor = conn.cursor(MySQLdb.cursors.DictCursor) > >cursor.execute('SHOW SLAVE STATUS') > >result = cursor.fetchone() > >cursor.close() > > > > I am unable to Impement t