1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-17 19:22:28 +08:00

doc: add document and example for IsPingConnected and IsTelnetConnected

This commit is contained in:
dudaodong
2023-04-19 11:48:28 +08:00
parent c137428b9e
commit f73c7e7e86
3 changed files with 177 additions and 5 deletions

View File

@@ -44,6 +44,8 @@ import (
- [HttpPut<sup>Deprecated</sup>](#HttpPut) - [HttpPut<sup>Deprecated</sup>](#HttpPut)
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch) - [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
- [ParseHttpResponse](#ParseHttpResponse) - [ParseHttpResponse](#ParseHttpResponse)
- [IsPingConnected](#IsPingConnected)
- [IsTelnetConnected](#IsTelnetConnected)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -896,3 +898,75 @@ func main() {
fmt.Println(toDoResp) fmt.Println(toDoResp)
} }
``` ```
### <span id="IsPingConnected">IsPingConnected</span>
<p>checks if can ping the specified host or not.</p>
<b>Signature:</b>
```go
func IsPingConnected(host string) bool
```
<b>Example:</b>
```go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
result1 := netutil.IsPingConnected("www.baidu.com")
result2 := netutil.IsPingConnected("www.!@#&&&.com")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
```
### <span id="IsTelnetConnected">IsTelnetConnected</span>
<p>Checks if can telnet the specified host or not.</p>
<b>Signature:</b>
```go
func IsTelnetConnected(host string, port string) bool
```
<b>Example:</b>
```go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
result1 := netutil.IsTelnetConnected("www.baidu.com", "80")
result2 := netutil.IsTelnetConnected("www.baidu.com", "123")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
```

View File

@@ -44,6 +44,8 @@ import (
- [HttpPut<sup>Deprecated</sup>](#HttpPut) - [HttpPut<sup>Deprecated</sup>](#HttpPut)
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch) - [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
- [ParseHttpResponse](#ParseHttpResponse) - [ParseHttpResponse](#ParseHttpResponse)
- [IsPingConnected](#IsPingConnected)
- [IsTelnetConnected](#IsTelnetConnected)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -898,3 +900,75 @@ func main() {
fmt.Println(toDoResp) fmt.Println(toDoResp)
} }
``` ```
### <span id="IsPingConnected">IsPingConnected</span>
<p>检查能否ping通主机。</p>
<b>函数签名:</b>
```go
func IsPingConnected(host string) bool
```
<b>示例:</b>
```go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
result1 := netutil.IsPingConnected("www.baidu.com")
result2 := netutil.IsPingConnected("www.!@#&&&.com")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
```
### <span id="IsTelnetConnected">IsTelnetConnected</span>
<p>检查能否telnet到主机。</p>
<b>函数签名:</b>
```go
func IsTelnetConnected(host string, port string) bool
```
<b>示例:</b>
```go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
result1 := netutil.IsTelnetConnected("www.baidu.com", "80")
result2 := netutil.IsTelnetConnected("www.baidu.com", "123")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
```

View File

@@ -178,3 +178,27 @@ func ExampleConvertMapToQueryString() {
// Output: // Output:
// a=1&b=2&c=3 // a=1&b=2&c=3
} }
func ExampleIsPingConnected() {
result1 := IsPingConnected("www.baidu.com")
result2 := IsPingConnected("www.!@#&&&.com")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
func ExampleIsTelnetConnected() {
result1 := IsTelnetConnected("www.baidu.com", "80")
result2 := IsTelnetConnected("www.baidu.com", "123")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}