| Old fashioned S010 ( @ 2009-07-01 11:19:00 |
| Entry tags: | fun, i did it for teh lulz, programming, shell, sockets, software |
Mou KaKaLLIku <3
tnamed
Aka trivial name daemon. I can never remember what IP addresses comps on my LAN have, an obvious solution is to add ip->hostname mappings to /etc/hosts file. But wtf, the computer should make my life easier not add more problems. And then you'll have to use static IP addresses or tell DHCP server to always assign the same IPs for certain MACs.
When you run tnamed, it:
- acquires the list of IP address that the machine has
- for each of the IP addresses, it broadcasts to the subnet 255.255.255.0 a message telling that it's located at that IP address :D Makes no sense, right? Example: a machine has a hostname of "slowpoke" and IP addresses 192.168.0.1, 89.191.97.180, then it will broadcast a message "slowpoke@192.168.0.1" to every host in 192.168.0 and "slowpoke@89.191.97.180" to every host in 89.191.97
- It then broadcasts a request for other hosts to announce themselves to the subnets the computer is connected to
- Then it goes into an endless loop waiting for incoming messages; when it gets a request to announce self, it does (1); when it gets other host's announcment, it adds an entry to /etc/hosts file
The hosts file may look something like this after tnamed:
127.0.0.1 slowpoke # Following entries added by tnamed 192.168.0.11 x2 192.168.0.10 d400 - When you kill tnamed, it restores the original /etc/hosts file
tnamed is intended as a zero-configuration daemon, it doesn't need any conf files or command line options. To use it, simply run it from root, on all the participating machines.
Say, you have three machines on you LAN, "host1", "host2" and "host3". Run tnamed on each of the comps. And then, being logged in on one of these comps, you can address the other two by names, liek ping host2
http://s010.lv/files/tnamed.c -- current version is somewhere like 0.5, the code is a little rough and I have one other thing I want to add for great justice =)
On BSD, compile like cc -DBSD -o tnamed tnamed.c, on linux, simply cc -o tnamed tnamed.c
lstree
s@slowpoke:0:~/src/svn/my/utils$ ./lstree -h
List files and directories in a fancy way.
usage: lstree [-d] [-m
Example output:
s@slowpoke:0:~/src/svn/my/utils$ ./lstree -g -F op
op/
`-.svn/
| `-prop-base/
| `-props/
| `-text-base/
| | `-INSTALL.svn-base
| | `-LICENSE.svn-base
| | `-Makefile.in.svn-base
| | `-README.svn-base
| | `-configure.ac.svn-base
| | `-op.conf_example.svn-base
| `-tmp/
| | `-prop-base/
| | `-props/
| | `-text-base/
| `-entries
| `-format
`-src/
...
shell2
Continuation of http://0x1392.livejournal.com/138681.htm
This is now a real command interpreter in that it actually parses the line entered, builds a parse tree and then executes the tree. Supported operators are
- &&
- AND operator, same as in common shells
- ||
- OR operator, same as in common shells
- ;
- execute mutliple commands in one line
- &
- execute in background
- ><
- suppress any kind of output (stdout and stderr); liek stfu! ><
- >
- redirect stdout to file
- ^>
- redirect stderr to file
- >>
- append stdout to file
- <
- redirect stdin from file
- !
- NOT operator, for use with AND and OR
Example run:
s:/home/s/src/svn/my/misc/shell$ ls asd && ls /
AND EVAL ls asd EVAL ls / trav_tree(): pid=17910
trav_tree(): pid=17910
ls: asd: No such file or directory
s:/home/s/src/svn/my/misc/shell$ ls asd || ls /
OR EVAL ls asd EVAL ls / trav_tree(): pid=17910
trav_tree(): pid=17910
ls: asd: No such file or directory
trav_tree(): pid=17910
altroot bin boot bsd bsd.rd dev etc
home mnt root sbin stand sys tmp
usr var
s:/home/s/src/svn/my/misc/shell$
http://s010.lv/files/shell.c, compiles like cc -lreadline -lcurse -o shell shell.c
clock.sh
Sort of a screen saver for console. Displays a clock which moves around the screen and bumps off the walls. Most interesting feature -- written in shell.
