开发者

How to find out if the pc is connected to a network?

Hi following problem: I want to write a small script on my notebook, which checks if a given host is online, but I'm not always connected to a networ开发者_JAVA百科k. So I want the script to do nothing if I'm not connected. How can I find out, whether I'm connected or not? My current solution is pinging google, but I'm not really happy with this.

Thank you for any suggestions Baju

P.S.: Should have mentioned: I'm running Ubuntu 10.10


The command to check if networking is configured properly differs based on Unix or Windows. If your host machine uses DHCP to get it's IP address and gateway information you can use the ipconfig (windows) or ifconfig (Unix) to query information about the network. Granted you'll have to parse their output.

edit: changed Unix command based on the code sample linked in the comment

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜