fix: 修复upf5002 telnet消息返回延迟导致命令行为不一致
This commit is contained in:
@@ -27,9 +27,8 @@ func (c *ConnTelnet) NewClient() (*ConnTelnet, error) {
|
||||
proto := "tcp"
|
||||
if strings.Contains(c.Addr, ":") {
|
||||
proto = "tcp6"
|
||||
c.Addr = fmt.Sprintf("[%s]", c.Addr)
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
|
||||
addr := net.JoinHostPort(c.Addr, fmt.Sprint(c.Port))
|
||||
|
||||
// 默认等待5s
|
||||
if c.DialTimeOut == 0 {
|
||||
@@ -76,6 +75,7 @@ func (c *ConnTelnet) RunCMD(cmd string) (string, error) {
|
||||
if _, err := conn.Write([]byte(cmd)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
@@ -230,6 +230,7 @@ func (s *TCPdump) UPFTrace(neType, neId, cmdStr string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
defer telnetClient.Close()
|
||||
telnetClient.RunCMD("") // 再次排空信息
|
||||
|
||||
// 命令拼装
|
||||
fileName := fmt.Sprintf("%s_%s_part_%s.pcap ", neInfo.NeType, neInfo.NeId, time.Now().Format("20060102150405"))
|
||||
@@ -250,11 +251,11 @@ func (s *TCPdump) UPFTrace(neType, neId, cmdStr string) (string, error) {
|
||||
|
||||
// 结果截取
|
||||
arr := strings.Split(output, "\r\n")
|
||||
if len(arr) == 2 {
|
||||
if len(arr) < 2 {
|
||||
return "", fmt.Errorf("trace pacp run failed")
|
||||
}
|
||||
if len(arr) > 3 {
|
||||
resMsg := arr[2]
|
||||
if len(arr) == 3 {
|
||||
resMsg := arr[1]
|
||||
// pcap trace: unknown input `f file UPF_001_part_2024-08-19...'
|
||||
// pcap trace: dispatch trace already enabled...
|
||||
// pcap trace: dispatch trace already disabled...
|
||||
|
||||
Reference in New Issue
Block a user