Reputation: 2763
How can I execute network commands on android like
ifconfig - ping etc
I used
Process process = Runtime.getRuntime().exec("/system/bin/ifconfig");
But the output was only the process ID
Upvotes: 0
Views: 1852
Reputation: 5457
ifconfig won't give you anything itself. you need to use netcfg
or ifconfig eth0
$ /system/bin/ifconfig
/system/bin/ifconfig
$ netcfg
netcfg
lo UP 127.0.0.1 255.0.0.0 0x00000049
dummy0 DOWN 0.0.0.0 0.0.0.0 0x00000082
rmnet0 DOWN 25.116.182.253 255.255.255.252 0x00000000
rmnet1 DOWN 0.0.0.0 0.0.0.0 0x00000000
rmnet2 DOWN 0.0.0.0 0.0.0.0 0x00000000
rmnet3 DOWN 0.0.0.0 0.0.0.0 0x00000000
rmnet4 DOWN 0.0.0.0 0.0.0.0 0x00000000
rmnet5 DOWN 0.0.0.0 0.0.0.0 0x00000000
rmnet6 DOWN 0.0.0.0 0.0.0.0 0x00000000
rmnet7 DOWN 0.0.0.0 0.0.0.0 0x00000000
usb0 DOWN 0.0.0.0 0.0.0.0 0x00001002
sit0 DOWN 0.0.0.0 0.0.0.0 0x00000080
ip6tnl0 DOWN 0.0.0.0 0.0.0.0 0x00000080
gannet0 DOWN 0.0.0.0 0.0.0.0 0x00001082
eth0 UP 192.168.1.141 255.255.255.0 0x00001043
$ ifconfig lo
ifconfig lo
lo: ip 127.0.0.1 mask 255.0.0.0 flags [up loopback running]
$ ifconfig eth0
ifconfig eth0
eth0: ip 192.168.1.141 mask 255.255.255.0 flags [up broadcast running multicast]
$
Upvotes: 2
Reputation: 13293
You need to use the getOutputStream()
method of the process
object instance. Any output created by the process will be readable on the output stream returned by that method.
Upvotes: 0