mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 21:30:16 +02:00
get tcp port information from banner
This commit is contained in:
parent
c5bbdb4cb5
commit
1275c6b1b5
3 changed files with 16 additions and 17 deletions
|
@ -55,14 +55,16 @@ func Run() (err error) {
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
return relay(c)
|
return relay(c)
|
||||||
},
|
},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013,9014,9015,9016,9017,9018", Usage: "ports of the relay"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.BoolFlag{Name: "debug", Usage: "increase verbosity (a lot)"},
|
cli.BoolFlag{Name: "debug", Usage: "increase verbosity (a lot)"},
|
||||||
cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
|
cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
|
||||||
cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
||||||
cli.StringFlag{Name: "relay", Value: "198.199.67.130", Usage: "address of the relay"},
|
cli.StringFlag{Name: "relay", Value: "198.199.67.130:9009", Usage: "address of the relay"},
|
||||||
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013,9014,9015,9016,9017,9018", Usage: "address of the relay"},
|
|
||||||
cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
||||||
}
|
}
|
||||||
app.EnableBashCompletion = true
|
app.EnableBashCompletion = true
|
||||||
|
@ -163,7 +165,6 @@ func send(c *cli.Context) (err error) {
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.GlobalBool("debug"),
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.GlobalBool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.GlobalString("relay"),
|
||||||
RelayPorts: strings.Split(c.GlobalString("ports"), ","),
|
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.GlobalBool("stdout"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -200,7 +201,6 @@ func receive(c *cli.Context) (err error) {
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.GlobalBool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.GlobalString("relay"),
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.GlobalBool("stdout"),
|
||||||
RelayPorts: strings.Split(c.GlobalString("ports"), ","),
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -215,12 +215,13 @@ func relay(c *cli.Context) (err error) {
|
||||||
debugString = "debug"
|
debugString = "debug"
|
||||||
}
|
}
|
||||||
ports := strings.Split(c.GlobalString("ports"), ",")
|
ports := strings.Split(c.GlobalString("ports"), ",")
|
||||||
|
tcpPorts := strings.Join(ports[1:], ",")
|
||||||
for i, port := range ports {
|
for i, port := range ports {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go func(portStr string) {
|
go func(portStr string) {
|
||||||
err = tcp.Run(debugString, portStr, c.GlobalString("ports"))
|
err = tcp.Run(debugString, portStr, tcpPorts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
var banner string
|
var banner string
|
||||||
conn, banner, err := tcp.ConnectToTCPServer("localhost:"+c.Options.RelayPorts[0], c.Options.SharedSecret)
|
conn, banner, err := tcp.ConnectToTCPServer("localhost:9001", c.Options.SharedSecret)
|
||||||
log.Debugf("banner: %s", banner)
|
log.Debugf("banner: %s", banner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||||
|
@ -283,9 +283,9 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection to %s", c.Options.RelayAddress)
|
||||||
var banner string
|
var banner string
|
||||||
conn, banner, err := tcp.ConnectToTCPServer(c.Options.RelayAddress+":"+c.Options.RelayPorts[0], c.Options.SharedSecret)
|
conn, banner, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
|
||||||
log.Debugf("banner: %s", banner)
|
log.Debugf("banner: %s", banner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||||
|
@ -323,7 +323,7 @@ func (c *Client) Receive() (err error) {
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
}
|
}
|
||||||
var banner string
|
var banner string
|
||||||
c.conn[0], banner, err = tcp.ConnectToTCPServer(c.Options.RelayAddress+":"+c.Options.RelayPorts[0], c.Options.SharedSecret)
|
c.conn[0], banner, err = tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
|
||||||
log.Debugf("banner: %s", banner)
|
log.Debugf("banner: %s", banner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||||
|
@ -414,8 +414,8 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
|
||||||
|
|
||||||
// connects to the other ports of the server for transfer
|
// connects to the other ports of the server for transfer
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(c.Options.RelayPorts) - 1)
|
wg.Add(len(c.Options.RelayPorts))
|
||||||
for i := 1; i < len(c.Options.RelayPorts); i++ {
|
for i := 0; i < len(c.Options.RelayPorts); i++ {
|
||||||
go func(j int) {
|
go func(j int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
c.conn[j], _, err = tcp.ConnectToTCPServer(
|
c.conn[j], _, err = tcp.ConnectToTCPServer(
|
||||||
|
@ -638,7 +638,7 @@ func (c *Client) updateState() (err error) {
|
||||||
// setup the progressbar
|
// setup the progressbar
|
||||||
c.setBar()
|
c.setBar()
|
||||||
c.TotalSent = 0
|
c.TotalSent = 0
|
||||||
for i := 1; i < len(c.Options.RelayPorts); i++ {
|
for i := 0; i < len(c.Options.RelayPorts); i++ {
|
||||||
go c.sendData(i)
|
go c.sendData(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,7 +742,7 @@ func (c *Client) sendData(i int) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if math.Mod(curi, float64(len(c.Options.RelayPorts)-1))+1 == float64(i) {
|
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
|
||||||
// check to see if this is a chunk that the recipient wants
|
// check to see if this is a chunk that the recipient wants
|
||||||
usableChunk := true
|
usableChunk := true
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
|
|
|
@ -26,8 +26,7 @@ func TestCroc(t *testing.T) {
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
SharedSecret: "test",
|
SharedSecret: "test",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost",
|
RelayAddress: "localhost:8081",
|
||||||
RelayPorts: []string{"8081", "8082", "8083"},
|
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
DisableLocal: true,
|
DisableLocal: true,
|
||||||
|
@ -41,8 +40,7 @@ func TestCroc(t *testing.T) {
|
||||||
IsSender: false,
|
IsSender: false,
|
||||||
SharedSecret: "test",
|
SharedSecret: "test",
|
||||||
Debug: true,
|
Debug: true,
|
||||||
RelayAddress: "localhost",
|
RelayAddress: "localhost:8081",
|
||||||
RelayPorts: []string{"8081", "8082", "8083"},
|
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
DisableLocal: true,
|
DisableLocal: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue