/***************************************************************************************
* Linux udhcp client (udhcpc) get IP at anytime
* 声明:
* 对于ARM产品,之前在想如何能够做到像PC机那样,当网线插入RJ45座的时候,就能自动获
* 取到IP,这样就无需另外去设置IP等相关信息,主要考虑到嵌入式产品有时候可能根本没有图形
* 界面,如果不能自动连接网络,只能通过调试口去设置网络,不合情理,直觉认为可能需要依赖
* udhcpc来做这件事,于是发现了udhcpc命令的-b参数。
*
* 2015-10-21 晴 深圳 南山平山村 曾剑锋
**************************************************************************************/ 一、参考文章:
. Busybox Command Help
http://busybox.net/downloads/BusyBox.html
. udhcpc 后台运行的方法【总结】
http://www.360doc.com/content/12/0323/09/9106558_196861856.shtml
. udhcpc running in the background [Summary]
http://www.programmershare.com/2365338/ 二、busybox udhcpc help:
udhcpc [-Cfbnqtvo] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]
[-p pidfile] [-r IP] [-s script] [-O dhcp-option]...
-V,--vendorclass=CLASSID Vendor class identifier
-i,--interface=INTERFACE Interface to use (default eth0)
-H,-h,--hostname=HOSTNAME Client hostname
-c,--clientid=CLIENTID Client identifier
-C,--clientid-none Suppress default client identifier
-p,--pidfile=file Create pidfile
-r,--request=IP IP address to request
-s,--script=file Run file at DHCP events (default /usr/share/udhcpc/default.script)
-t,--retries=N Send up to N request packets
-T,--timeout=N Try to get a lease for N seconds (default )
-A,--tryagain=N Wait N seconds (default ) after failure
-O,--request-option=OPT Request DHCP option OPT (cumulative)
-o,--no-default-options Do not request any options (unless -O is also given)
-f,--foreground Run in foreground
-b,--background Background if lease is not immediately obtained
-S,--syslog Log to syslog too
-n,--now Exit with failure if lease is not immediately obtained
-q,--quit Quit after obtaining lease
-R,--release Release IP on quit
-a,--arping Use arping to validate offered address 三、udhcpc -b test:
root@freescale ~$ ifconfig
eth0 Link encap:Ethernet HWaddr 1E:ED:::1A:B3
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 B) TX bytes: (0.0 B) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (390.9 KiB) TX bytes: (390.9 KiB)
root@freescale ~$ udhcpc -b (这里我并没有用udhcpc -b -i eth0 -p /var/run/udhcpc.pid -R &)
udhcpc (v1.20.2) started
Sending discover...
Sending discover...
Sending discover...
No lease, forking to background
root@freescale ~$ PHY: : - Link is Up - /Full
root@freescale ~$ ifconfig (插入网线之后,最好等上2-4秒才能获取到IP)
eth0 Link encap:Ethernet HWaddr 1E:ED:::1A:B3
inet addr:10.0.1.52 Bcast:10.0.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (1.2 KiB) TX bytes: (656.0 B) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (390.9 KiB) TX bytes: (390.9 KiB)

Linux udhcp client (udhcpc) get IP at anytime的更多相关文章

  1. Linux防火墙:iptables禁IP与解封IP常用命令

    在Linux服务器被攻击的时候,有的时候会有几个主力IP.如果能拒绝掉这几个IP的攻击的话,会大大减轻服务器的压力,说不定服务器就能恢复正常了. 在Linux下封停IP,有封杀网段和封杀单个IP两种形 ...

  2. Linux下设置网卡静态ip

    Linux下设置网卡静态ip 如果是服务器版,没有图形界面只用用命令行修改配置文件 如果是客户端版本,可以用图形界面 配置的前提是要在root用户下才能重启网卡服务 图形界面: system-conf ...

  3. Linux SocketCan client server demo hacking

    /*********************************************************************** * Linux SocketCan client se ...

  4. Android Linux自带iptables配置IP访问规则

    利用Linux自带iptables配置IP访问规则,即可做到防火墙效果

  5. Linux服务器tomcat无法通过ip加端口访问

    Linux服务器tomcat无法通过ip加端口访问 防火墙开放端口 # Firewall configuration written by system-config-firewall# Manual ...

  6. Linux 最小化安装后IP的配置(手动获取静态IP地址)

    一.图形化界面配置(假设为电脑A) 如果你的Linux安装有图形化界面,那么通过以下方式来配置: 我这里是有两块网卡,第一个网卡在上篇中已经通过DHCP来配置了:Linux 最小化安装后IP的配置(D ...

  7. Linux 最小化安装后IP的配置(DHCP获取IP地址)

    图形化Linux的DHCP好配置,我就不讲了.主要将一下Linux最小化安装后IP的配置: linux最小化安装后没有ifconfig这个命令: yum install net-tools.x86_6 ...

  8. Golang client绑定本地IP和端口

    有时需要指定网络通信时本地使用的IP地址和端口号. 在Go语言中可通过定义 Dialer 中LocalAddr 成员实现. Dialer结构定义如下: // A Dialer contains opt ...

  9. Linux环境下如何配置IP地址、MAC地址

    Linux环境下如何配置IP地址.MAC地址 1.配置IP地址 进入配置IP地址路径,进行修改即可 cd /etc/network vim interface 加入以下内容: iface eth0 i ...

随机推荐

  1. 【Cocos2dx3.x Lua】图片异步加载

    一.说明     异步加载就是把消耗程序时间比较大的加载操作放到其他线程中,待加载完毕后通过回调函数的方式通知主线程.   addImageAsync函数实现(Cocos2dx 3.3) Link:  ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 Solution

    A. Hard to prepare 题意:有n个客人做成一圈,有$2^k$种面具,对于每种面具有一种面具不能使相邻的两个人戴,共有多少种做法. 思路: 把题意转化成相邻的人不能带同种面具.总数为$( ...

  3. 字王4K云字库入驻github

    字王4K云字库入驻github 网址:https://github.com/ziwang-com/zw4kFont   2015.3.28,字王4K云字库入驻github,原本或早或晚,不过这几天在g ...

  4. python一段代码 感受一下

    class T():    def aa(self):        write = 1        print '123' class B():            def hehe(self) ...

  5. C#反射——模仿ParameterInterceptor(ashx处理程序)

    反射工具类请参见:https://www.cnblogs.com/threadj/p/10535796.html using System; using System.Collections.Gene ...

  6. C++11多线程教学

    转自:http://www.cnblogs.com/lidabo/p/3908705.html 本篇教学代码可在GitHub获得:https://github.com/sol-prog/threads ...

  7. CentOS下安装JDK,Tomcat,Redis,Mysql,及项目发布

    上传文件到服务器,安装lrzsz , 可以将本地的文件上传到linux系统上. 如果是CentOS则可以用yum install lrzsz 命令安装,更方便. 或:yum -y install lr ...

  8. 获取WebView加载的网页内容并进行动态修改

    http://www.jianshu.com/p/3f207a8e32cb [Android]WebView读取本地图片 http://www.cnblogs.com/kimmy/p/4769788. ...

  9. PHP Fatal error: Uncaught Error: Call to undefined function pcntl_fork().. 开启php pcntl扩展实现多进程

    在使用函数pcntl_fork()时报错  Fatal error: Uncaught Error: Call to undefined function pcntl_fork()....,原因是没有 ...

  10. HTTP-java模拟Get请求小栗子

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...