Hello Friends,
I have a small IP scan code written in shell script,i want my code should get executed as kernel get booted....plz tell how can i insert that code into new kernel...what are the steps should i follow.....

My aim of putting the IP scan code in kernel the idea behind that is as kernel get booted simultaneously my IP scan code will get executed ok....the resulting alive IP.....i want to connect that IP... is this possible if yes how....In simple way i want to toggle betwen 2 DHCP server's one from win & 2nd from Linux.

Is there any other way can i handle this....

Windows Server 2003 Ubuntu Linux
DHCP server DHCP server
| |
| |
_________________________________________
| |
Client
Can Choose
which DHCP he wants

Dani AI

Generated

Short answer for : don’t try to “insert” a shell script into the kernel. Kernel modules are compiled kernel‑space code (C) and are not a place to run shell scripts — kernel code has no shell environment and bugs there crash the whole system. If your goal is “run this IP-scan when the system boots and act on the results,” keep the scanner in userspace and run it from the init system. (docs.kernel.org)

A modern, robust way is to wrap your script in a systemd oneshot service that waits for the network to be online, then runs the scanner once. Example unit (put in /etc/systemd/system/ipscan.service):

[Unit]
Description=Run IP scan after network is up
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/ipscan.sh

[Install]
WantedBy=multi-user.target

Enable with systemctl enable --now ipscan.service. network-online.target is the correct place to wait for a routable IP (and has specific wait services for NetworkManager or systemd-networkd). (systemd.io)

If you’re on an older system (no systemd) you can use a proper SysV init script or /etc/rc.local (legacy) or a @reboot cron job — but these are less flexible and rc.local is considered compatibility/legacy on many distros. Prefer a proper unit/script that declares its ordering rather than relying on rc.local. (cyberciti.biz)

About the DHCP toggle idea: DHCP clients choose between offers — the client collects DHCPOFFERs and then selects one server (the client includes the chosen server’s identifier in DHCPREQUEST). You cannot reliably force a client to accept “server A” vs “server B” purely at the client without network-level changes (VLANs, delaying offers, different MACs, or controlling which server answers). For protocol details see RFC 2131. (datatracker.ietf.org)

Practical workflow: run your scanner as a userspace script after the interface is up (systemd unit or NetworkManager dispatcher hooks). If you want to react to DHCP events, use the DHCP client hooks (dhclient scripts / exit-hooks) or distro-specific network dispatcher hooks to parse the lease and server identifier and then perform whatever connection logic you need. That keeps complexity out of the kernel and makes development, logging and debugging far easier. (kb.isc.org)

Recommended Answers

All 3 Replies

Hello Friends,
I have a small IP scan code written in shell script,i want my code should get executed as kernel get booted....plz tell how can i insert that code into new kernel...what are the steps should i follow.....

The only thing that you can insert into a Linux kernel are kernel modules which are written in C.

Check out this link:

http://tldp.org/LDP/lkmpg/2.6/html/

If you want to execute the script on boot then that's a different story.

http://www.linuxforums.org/forum/redhat-fedora-linux-help/24951-start-script-boot.html

Thanks Gerard i followed ur links & i got to no...how to make module...but one question...i want to add my new module in new kernel...how to do that and how to place that module that execute at last of the all init program...can u help me....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.