Skip to content

Commit d02217a

Browse files
committed
feat: add -S flag to specify source address in ping CLI
The ping command now supports a `-S` option to send ICMP echo requests from a specific source address. The flag value is assigned to `pinger.Source`, and an example has been added to the CLI usage text. Signed-off-by: Steven Normore <[email protected]>
1 parent 3b66532 commit d02217a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cmd/ping/ping.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Examples:
2828
# ping google specified interface
2929
ping -I eth1 www.goole.com
3030
31+
# ping google from a specified source address
32+
ping -S 192.168.1.100 www.google.com
33+
3134
# Send a privileged raw ICMP ping
3235
sudo ping --privileged www.google.com
3336
@@ -45,6 +48,7 @@ func main() {
4548
size := flag.Int("s", 24, "")
4649
ttl := flag.Int("l", 64, "TTL")
4750
iface := flag.String("I", "", "interface name")
51+
src := flag.String("S", "", "source address")
4852
tclass := flag.Int("Q", 192, "Set Quality of Service related bits in ICMP datagrams (DSCP + ECN bits). Only decimal number supported")
4953
privileged := flag.Bool("privileged", false, "")
5054
flag.Usage = func() {
@@ -100,7 +104,7 @@ func main() {
100104
pinger.InterfaceName = *iface
101105
pinger.SetPrivileged(*privileged)
102106
pinger.SetTrafficClass(uint8(*tclass))
103-
107+
pinger.Source = *src
104108
fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr())
105109
err = pinger.Run()
106110
if err != nil {

0 commit comments

Comments
 (0)