Chit chat

======

Screenshot - 06172014 - 10:01:35 AM


Just finished running the slackeware 14.1 update on my old Pentium 1 586. The wordpress update is taking a bit longer. Have tried to install all the old CL favorites like sc, but my favorite install is Freebasic. Have been able to port so much of my old software. Need to copy all my new batch files especially the page scrapers. Also installed is the web server for use as a doc server. When I did the install I did it with a pxeboot to a directory on the web server and the internet did the rest. Might be interesting if I could get iscsi or aoe to work and make the local hd unneeded. That is for another day. Using a compact flash for the drive now. So quiet. Also made an atx to at power cable so I could run the system on battery if needed. What does ‘obsolete’ mean? have dnsmasq working on it.
 If you are coding just to code, consider other opportunities There is a lot more to it than just slinging code unless you are just doing it for your own enjoyment. To be honest, if you go to work for a company you will not be choosing what language you use, My first real job was s a maintenance programmer. They had one programming language I was familiar with, but had to learn a completely new language to do my job. Fortunately, having used several languages, I was able to adapt. Just a grain of salt. .
Remember #caldera , #SCO and etc. Guess they forgot they gave out their source code. #linux
#IBM
You heard of B.C. This is B. A.  Before #Arduino. #hardware
Sous vide #arduino prototype
Normally we avoid posting anything Microsoft, but today we are going to make an exception.
When is the best time to get a free computer? When marriages or couples break apart and when MSWindows users think they need a new machine because the operating system requires beefier hardware. Acquired this old P3 for free from a couple breakup. Wiped the drive and put Linux on it.

Developed this simple wedding registry using Visual Basic on a i386 in the early days of gui for my then employer. Got me and interview to work with IT but accepted another companies offer.. Need to go back and code again.

Early dual cpu (aka dual core) system that was set up as a router. A collectors item.

—————————————-

Ever go somewhere and you need to have several systems be able to access their network, but they say all you cn have is one Ipaddress. An Ipaddress is like a phone number for a computer.  You can only have one per system under normal circumstances. Here with an extra system, we will show you how to do this.

A multitude of reasons exist as to why one would want to build a custom router vs. suffer with the performance, reliability issues, and limitations of an off-the-shelf solution. In the spirit of keeping this post short, I won’t launch into a long diatribe on the pros and cons of each here, but I have plenty of thoughts on this, so if you are interested, just ask.

What we are about to do is configure an incredibly fast and stable router/gateway solution for your home/office in about 15 minutes. (Note: This post assumes you already have your machine loaded up with a fresh copy of Ubuntu 14.04 or an equivalent and you have the two needed NICs installed.) This is not a firewall.

First, let’s make three initial assumptions:

eth0 is the public interface (the Cable/DSL modem is attached to this NIC)
eth1 is the private interface (your switch is connected to this NIC)
All of the client computers, servers, WAPs, etc. are connected to the switch

Let’s get started with the configuration. Set your timer and type quickly! 🙂

1.) Configure the network interfaces
You may need to make sure for older systems that plug and play os is enabled. Change the “address”, “netmask”, and “broadcast” values to match your internal network preferences. They must be different from the host aka wan network.

sudo nano -w /etc/network/interfaces
# The external WAN interface (eth0) public
allow-hotplug eth0
iface eth0 inet dhcp

# The internal LAN interface (eth1) private
allow-hotplug eth1
iface eth1 inet static
address 10.1.10.1
netmask 255.255.255.0
network 10.1.10.0
broadcast 10.1.10.255

2. Install and configure DNSmasq
DNSmasq is DNS forwarder and DHCP server. Change “domain” to the FQDN of your network and “dhcp-range” to the desired range of DHCP addresses you would like your router to serve out to clients.

sudo apt-get install dnsmasq

nano -w /etc/dnsmasq.conf
interface=eth1
listen-address=127.0.0.1
domain=home.andreimatei.com
0dhcp-range=10.1.10.100,10.1.10.110,12h

3.) Enable IP Forwarding
Uncomment the following line:

sudo nano -w /etc/sysctl.conf
net.ipv4.ip_forward=1

4.) Configure iptables
We create a file called /etc/iptables.rules and put this rule set inside of it.  As an example, this set includes allowing tcp traffic in from the outside world on port 222 (I run SSH on this alternate port) and also port-forwards tcp port 50,000 to an internal machine with the ip of 10,1,10.3 Use this as a guide for your own rules.

Note that when you do this access to the system will be locked down amd ssh not work. Infact a ping to the system will be ignored.

sudo nano -w /etc/iptables.rules

*nat
-A PREROUTING -i eth0 -p tcp -m tcp –dport 50000 -j DNAT –to-destination 192.168.0.3:50000
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT

*filter
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp –dport 222 -j ACCEPT
-A INPUT -i eth0 -j DROP
-A FORWARD -i eth0 -p tcp -m tcp –dport 50000 -m state –state NEW -j ACCEPT
COMMIT

5.) Activate your iptables rules

iptables-restore < /etc/iptables.rules

6.) Ensure iptables rules start on boot
Insert the following line into your /etc/network/interfaces file right underneath “iface lo inet loopback”

nano -w /etc/network/interfaces
pre-up iptables-restore < /etc/iptables.rules

7.) Reboot and Verify
That’s it! After a reboot, you should now have a very basic Linux Router/Gateway for your network.

router:~$ sudo nano -w /etc/iptables.rules
[sudo] password for eddie:

router:~$ sudo iptables-restore < /etc/iptables.rules

router:~$ sudo nano -w /etc/network/interfaces

router:~$ sudo reboot

router:~$
Broadcast message from router
(/dev/pts/0) at 8:44 …

The system is going down for reboot NOW!
Connection to 192.168.1.102 closed by remote host.

Connection to 192.168.1.102 closed.

You should be able to use your router now.

NOte: you should be able to do this with most any distro, but using different commands. Wnat to try this with a pentium 1 and Slackware. Did not have time to trying before putting this article out.

oedt01:~$ ssh 192.168.1.102
192.168.1.102’s password:
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-53-generic i686)

* Documentation:  https://help.ubuntu.com/
Last login: Fri May 29 07:39:02 2015

router:~$ cd /etc

router:/etc$ sudo vim  dnsmasq.conf
[sudo] password for eddie:

router:/etc$ sudo vim /etc/network/interfaces

router:/etc$ sudo vim  dnsmasq.conf

router:/etc$ sudo service dnsmasq restart

* Restarting DNS forwarder and DHCP server dnsmasq                      [ OK ]
router:/etc$ sudo service dnsmasq sttus
Usage: /etc/init.d/dnsmasq {start|stop|restart|force-reload|dump-stats|status}
router:/etc$ sudo service dnsmasq status
* Checking DNS forwarder and DHCP server dnsmasq                                * (running)

Connect to the client side. We used a tablet and crossover adapter to check dnsmasq. You could use a network switch also.

Note: if you get a usb to ethernet adapter, you can make a mice little Raspberry Pi router. You could also use a wireless card for the lan, but that requires a bit more security,

You may also want to setup webmin to make managing the router easier.

—————————————-

It is not required, but installing webmin can make managing the router easier.

router:/etc$ cd

router:~$ wget http://prdownloads.sourceforge.net/webadmin/webmin_1.750_all.deb
–2015-05-29 08:15:22–  http://prdownloads.sourceforge.net/webadmin/webmin_1.750_all.deb
Resolving prdownloads.sourceforge.net (prdownloads.sourceforge.net)… 216.34.181.59
Connecting to prdownloads.sourceforge.net (prdownloads.sourceforge.net)|216.34.181.59|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: http://downloads.sourceforge.net/project/webadmin/webmin/1.750/webmin_1.750_all.deb [following]
–2015-05-29 08:15:22–  http://downloads.sourceforge.net/project/webadmin/webmin/1.750/webmin_1.750_all.deb
Resolving downloads.sourceforge.net (downloads.sourceforge.net)… 216.34.181.59
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://hivelocity.dl.sourceforge.net/project/webadmin/webmin/1.750/webmin_1.750_all.deb [following]
–2015-05-29 08:15:22–  http://hivelocity.dl.sourceforge.net/project/webadmin/webmin/1.750/webmin_1.750_all.deb
Resolving hivelocity.dl.sourceforge.net (hivelocity.dl.sourceforge.net)… 74.50.101.106
Connecting to hivelocity.dl.sourceforge.net (hivelocity.dl.sourceforge.net)|74.50.101.106|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 26195366 (25M) [application/octet-stream]
Saving to: ‘webmin_1.750_all.deb’

100%[======================================>] 26,195,366   586KB/s   in 42s

2015-05-29 08:16:04 (614 KB/s) – ‘webmin_1.750_all.deb’ saved [26195366/26195366]

router:~$ sudo dpkg -i webmin_1.750_all.debSelecting previously unselected package webmin.
(Reading database … 57184 files and directories currently installed.)
Preparing to unpack webmin_1.750_all.deb …
Unpacking webmin (1.750) …
dpkg: dependency problems prevent configuration of webmin:
webmin depends on libnet-ssleay-perl; however:
Package libnet-ssleay-perl is not installed.
webmin depends on libauthen-pam-perl; however:
Package libauthen-pam-perl is not installed.
webmin depends on libio-pty-perl; however:
Package libio-pty-perl is not installed.
webmin depends on apt-show-versions; however:
Package apt-show-versions is not installed.

dpkg: error processing package webmin (–install):
dependency problems – leaving unconfigured
Processing triggers for ureadahead (0.100.0-16) …
Errors were encountered while processing:
webmin

There will probably be an error. There is an easy fix.

router:~$ sudo apt-get upgrade -f
Reading package lists… Done
Building dependency tree
Reading state information… Done
Correcting dependencies… Done
Calculating upgrade… Done
The following NEW packages will be installed:
apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl
libnet-ssleay-perl
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 425 kB of archives.
After this operation, 1,752 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main libnet-ssleay-perl i386 1.58-1 [242 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ trusty/universe libauthen-pam-perl i386 0.16-2build3 [27.8 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ trusty/main libio-pty-perl i386 1:1.08-1build4 [36.7 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ trusty/main libapt-pkg-perl i386 0.1.29build1 [84.5 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ trusty/universe apt-show-versions all 0.22.3 [33.9 kB]
Fetched 425 kB in 1s (226 kB/s)
Selecting previously unselected package libnet-ssleay-perl.
(Reading database … 82053 files and directories currently installed.)
Preparing to unpack …/libnet-ssleay-perl_1.58-1_i386.deb …
Unpacking libnet-ssleay-perl (1.58-1) …
Selecting previously unselected package libauthen-pam-perl.
Preparing to unpack …/libauthen-pam-perl_0.16-2build3_i386.deb …
Unpacking libauthen-pam-perl (0.16-2build3) …
Selecting previously unselected package libio-pty-perl.
Preparing to unpack …/libio-pty-perl_1%3a1.08-1build4_i386.deb …
Unpacking libio-pty-perl (1:1.08-1build4) …
Selecting previously unselected package libapt-pkg-perl.
Preparing to unpack …/libapt-pkg-perl_0.1.29build1_i386.deb …
Unpacking libapt-pkg-perl (0.1.29build1) …
Selecting previously unselected package apt-show-versions.
Preparing to unpack …/apt-show-versions_0.22.3_all.deb …
Unpacking apt-show-versions (0.22.3) …
Processing triggers for man-db (2.6.7.1-1ubuntu1) …
Setting up libnet-ssleay-perl (1.58-1) …
Setting up libauthen-pam-perl (0.16-2build3) …
Setting up libio-pty-perl (1:1.08-1build4) …
Setting up libapt-pkg-perl (0.1.29build1) …
Setting up apt-show-versions (0.22.3) …
** initializing cache. This may take a while **
Setting up webmin (1.750) …
Webmin install complete. You can now login to https://router:10000/
as root with your root password, or as any user who can use sudo
to run commands as root.
Processing triggers for ureadahead (0.100.0-16) …

—————————————-

How can I compile a simple C or C++ program on Linux operating systems using bash Terminal application?

Tutorial details

Difficulty: easy
Root privileges No
Requirements GNU C/C++ compiler
Estimated completion time 10m

GNU C and C++ compiler collection
Development tools
Development libraries
IDE or text editor to write programs

Part 1: Install C/C++ compiler and related tools

To compile a C or C++ program on any Linux distro such as Ubuntu, Red Hat, Fedora, Debian and other Linux distro you need to install:

>Fedora, Redhat, Centos, Or Scientific linux:

# yum groupinstall ‘Development Tools’

>Debian, Ubuntu, or Mint

$ sudo apt-get update
$ sudo apt-get install build-essential manpages-dev

To verify the install, type the following commands to display the version number and location of the compiler on Linux:

$ whereis gcc
$ which gcc
$ gcc –version

Sample outputs:

$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc

$ whereis g++
g++: /usr/bin/g++ /usr/bin/X11/g++

$ gcc –version
gcc (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc
gcc: fatal error: no input files
compilation terminated.
$

Part 2:  GNU C compiler on Linux. Create a file called demo.c using a text editor such as vim or nano

#include<stdio.h>
/* demo.c: My first C program on a Linux
*/
int main(void) {
printf(“Hello! This is a test program.\n”);
return 0;
}

Save as demo.c

How do I compile the program on Linux?

Use any one of the following syntax to compile the program called demo.c:

$ cc program-source-code.c -o executable-file-name

OR

$ gcc program-source-code.c -o executable-file-name

In this example, compile demo.c, enter:
$ cc demo.c -o demo

If there is no error in your code or C program then the compiler will successfully create an executable file called demo in the current directory, otherwise you need fix the code. To verify this, type:

$ ls -al demo*
-rwxr-xr-x 1 eddie eddie 4884 May 31 20:35 demo
-rw-r–r– 1 eddie eddie  149 May 31 20:35 demo.c

How do I run or execute the program called demo on Linux? Just simply type the the program name

$ ./demo

OR

$ /path/to/demo

$ ./demo
Hello! This is a test program.

Part 3: GNU C++ compiler on Linux

Create a program called demo.cpp as follows:

#include “iostream”
// demo2.C – Sample C++ program
int main(void) {
std::cout << “Hello! This is a C++ program.\n”;
return 0;
}

To compile this program, enter:

$ g++ demo.cpp -o demo

To run this program, type: ./demo

$ ./demo
Hello! This is a C++ program.

Part 4: More information.
How do I generate optimized code on a Linux machine?

The syntax is as follows C compiler:
cc -O input.c -o executable
The syntax is as follows C++ compiler:
g++ -O -Wall input.C -o executable
How do I compile a C program that uses math functions?

The syntax is as follows when need pass the -lm option with gcc to link with the math libraries:
cc myth1.c -o executable -lm
How do I compile a C++ program that uses Xlib graphics functions?

The syntax is as follows when need pass the -lX11 option with gcc to link with the Xlib libraries:
g++ fireworks.C -o executable -lX11
How do I compile a program with multiple source files?

The syntax is as follows if the source code is in several files (such as light.c, sky.c, fireworks.c):
cc light.c sky.c fireworks.c -o executable
C++ syntax is as follows if the source code is in several files:
g++ ac.C bc.C file3.C -o my-program-name

See gcc(1) : Linux and Unix man page for more information.

$ man gcc

—————————————-

Yet another weather picture grabber and the the picture is converted to ascii.

#!/bin/bash

#Set variables
DOWNLOAD_DIR=/tmp/weather/
WEATHER_GIF=http://archive.wfaa.com/weather/images/core/animated-loops/comp/880×495/new_tarrant.gif

COUNTER=0

#check for  download directory
if [ ! -d “$DOWNLOAD_DIR” ]; then
mkdir -p $DOWNLOAD_DIR
fi

#remove old files
rm  $DOWNLOAD_DIR/*gif
rm  $DOWNLOAD_DIR/*.png
rm  $DOWNLOAD_DIR/*.txt

#get weather gif
wget $WEATHER_GIF -O “${DOWNLOAD_DIR}map.gif”

#extract gif to png
convert -coalesce “${DOWNLOAD_DIR}/map.gif” “${DOWNLOAD_DIR}/map.png”

#convert images to text
for i in $DOWNLOAD_DIR/map-*; do
img2txt -f utf8 -W 100 -H 30 $i > $i.txt
done

#display images
while [ $COUNTER -lt 5 ] ; do
for i in $DOWNLOAD_DIR/map-*.txt; do
printf ’33[1;1H’
cat $i
sleep 0.5
done
let COUNTER=COUNTER+1
done

—————————————-

 

There are many parts to home automation but the main need is to be able to turn something on or off. Without that the rest is meaningless. Let us start with a simple light switch that you can control manually. The off position we will call zero and the on position we will call the one state.

 

Of course the purpose of home automation is for you not to have to manually turn off or on a switch. So we can get an electronic part known as a switching transistor to do the job for us with the help of a computing device that we can program. These diagrams are way over simplified to make things simpler. We could ask the computer to turn off all the leds with a command like out 888,0 and if any leds were on, they would immediately turn off.

 

The again, we could issue a command to turn them all on with out 888,255

 

Then you would want to turn them off and on individually also. Then you would either write some code or have a per-written program to do it for you and have appliances turn on or off at your will. Of course once you have your programming arranged, you can control the leds or any kind of home appliance or anything else at will. That is when interesting things can start happening if you want them to.

That ends part one.  Next time we will dig a little deeper using sensors such as a computer based thermometer as part of the mix.

—————————————-

In the real world. you probably would not be building any electronics. You could purchase network based control boxes. Most of the devices would be controlled by the time of day or manually controlled like a remote stereo system.

 

Many single sensors are cause and affect such as a garage door opener where the system waits for the detection of the controller and the proper security sequence. or you could have multiple sensors that workindependently but cuase the same affect such as a fire alarm or a security system

Screenshot from 2015-06-02 05:39:29

But let use get a bit more sophisticated. you could add a variety of sensors, but the most common might be the temperature sensor for control of your heating cooling system. The same idea could probably be adapted to a sous vide cooking system.

Now things have become a bit more complicated with additional sensors and control devices required. Also requires more complicated programming. You can see where systems can become very expensive.

We have only scratched the surface when it comes to sensors. That is part 2 for now,

—————————————-

Lovescope and monthly (use at your own risk)

####################################
# Horoscope Grabber
#
#===============================
# Assignments
# ——————————–
datafile=”rawcnn.txt”
let “flag = 0”
# end assignments
#=================================
#
# Get data file
#———————————
end=$(echo $1 | tr ‘[:lower:]’ ‘[:upper:]’)
elinks -dump “http://www.horoscopes.co.uk/$1/Love-Horoscope.php&#8221; > $datafile
#=================================
#
# Extract and display data
#———————————
while read line
do fdata[$a]=$line
echo $line | grep -q “Love Horoscope”
if [ $? -eq 0 ]; then
# header
clear
let “flag = 1”
fi
if [ $flag -eq 1 ]; then
echo $line | grep -q $end
if [ $? -eq 0 ]; then
let “flag = 0”
else
echo $line | grep -q “IMG”
if [ $? -eq 0 ]; then
let “response = donothing”
else
echo $line | sed ‘s/\[.*\]//’
fi
fi
fi
let “a += 1″
done < $datafile
# footer
echo ———————————————
echo $1
#===================================
# End.
####################################

####################################
# Horoscope Grabber
#
#===============================
# Assignments
# ——————————–
datafile=”rawcnn.txt”
let “flag = 0”
# end assignments
#=================================
#
# Get data file
#———————————
elinks -dump “http://www.horoscopes.co.uk/$1/Monthly-Horoscope.php&#8221; > $datafile
#=================================
#
# Extract and display data
#———————————
while read line
do fdata[$a]=$line
echo $line | grep -q “Monthly Horoscope”
if [ $? -eq 0 ]; then
# header
clear
let “flag = 1”
fi
if [ $flag -eq 1 ]; then
echo $line | grep -q “Horoscopes”
if [ $? -eq 0 ]; then
let “flag = 0”
else
echo $line | grep -q “IMG”
if [ $? -eq 0 ]; then
let “response = donothing”
else
echo $line | sed ‘s/\[.*\]//’
fi
fi
fi
let “a += 1”
done < $datafile
# footer
echo ———————————————
echo
#===================================
# End.
####################################

—————————————-

Sweet potato pie before topping.

yampie

Good day.

Advertisements