<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>linuxbuddies.com &#187; msyql</title>
	<atom:link href="http://linuxbuddies.com/tag/msyql/feed/" rel="self" type="application/rss+xml" />
	<link>http://linuxbuddies.com</link>
	<description>For linux documentations.</description>
	<lastBuildDate>Fri, 11 Sep 2009 10:11:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Collecting User IP!</title>
		<link>http://linuxbuddies.com/2009/01/03/collecting-user-ip/</link>
		<comments>http://linuxbuddies.com/2009/01/03/collecting-user-ip/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 07:14:44 +0000</pubDate>
		<dc:creator>Riyesh</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[cgi scripting]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[msyql]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[users IP]]></category>

		<guid isPermaLink="false">http://linuxbuddies.com/?p=272</guid>
		<description><![CDATA[A sample BASH CGI script for collecting IPs of your colleagues in your network.
Prerequisites 
1) apache/cgi configuration
2) a Mysql installation
Then create script &#8220;getip.sh&#8221; under &#8220;/var/www/cgi-bin/&#8221;  ( set location of cgi-bin directory  as per the apache configuration) 
#!/bin/bash #Getting IP address CGI-BASH-script#Jadu Saikia http://unstableme.blogspot.com/ #MySQL settings
# MHOME=  ( location of mysql ...]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-273" title="ip" src="http://linuxbuddies.com/wp-content/uploads/2009/01/ip.jpg" alt="ip" width="138" height="112" /><span style="color: #000000;">A sample BASH CGI script for collecting IPs of your colleagues in your network.</span></p>
<p><strong><span style="color: #000000;">Prerequisites </span></strong><br />
<span style="color: #000000;">1) apache/cgi configuration</span><br />
<span style="color: #000000;">2) a Mysql installation</span></p>
<p><span style="color: #000000;">Then create script &#8220;getip.sh&#8221; under &#8220;/var/www/cgi-bin/&#8221;  ( set location of cgi-bin directory  as per the apache configuration) </span></p>
<p style="padding-left: 30px;"><span style="font-size: x-small;"><span style="font-family: courier new,monospace;">#!/bin/bash</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">#Getting IP address CGI-BASH-script</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">#Jadu Saikia <a href="http://unstableme.blogspot.com/" target="_blank">http://unstableme.blogspot.com/</a></span><br style="font-family: courier new,monospace;" /> <br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">#MySQL settings</span></span></p>
<p style="padding-left: 30px;"><span style="font-size: x-small;"># MHOME=  ( location of mysql binary)<br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">MHOME=/usr/local/mysql/bin</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">HOST=127.0.0.1</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">USER=root</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">PASS=&#8221;"</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">DB=mydb</span><br style="font-family: courier new,monospace;" /> <br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">OWNER=$(echo &#8220;$QUERY_STRING&#8221; |awk -F &#8220;=&#8221; &#8216;{print $NF}&#8217;)</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">IP=$REMOTE_ADDR</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">#QUERY_STRING = Query information that follows the ? in the URL that referenced this script.</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">#REMOTE_ADDR = IP address of the remote host making the request</span><br style="font-family: courier new,monospace;" /><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">#HTML Output</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">echo &#8220;Content-type: text/html&#8221;</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">echo &#8220;&#8221;</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">echo &#8220;&lt;html&gt;&lt;head&gt;&lt;title&gt;YOUR IP&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;I am collecting the IPs&lt;/h1&gt;&lt;pre&gt;&#8221;;</span><br style="font-family: courier new,monospace;" /> <span style="font-family: courier new,monospace;">echo &#8220;IP: &lt;em&gt;$IP&lt;/em&gt;&lt;br /&gt;&#8221;</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">echo &#8220;You Are IP is : &lt;em&gt;$OWNER&lt;/em&gt;&lt;br /&gt;&#8221;</span><br style="font-family: courier new,monospace;" /> <br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">$MHOME/mysql -u$USER -h$HOST &#8211;password=$PASS -e &#8220;INSERT INTO mydb.ips(rdate,ip,owner) VALUES(NOW(),&#8217;$IP&#8217;,'$OWNER&#8217;)&#8221; $DB</span><br style="font-family: courier new,monospace;" /> <br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">echo &#8220;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;&#8221;;</span></span></p>
<p>Then</p>
<p><span style="color: #000000;">Create MySql Database for storing the data. </span></p>
<p><span style="color: #000000;">logon to mysql </span></p>
<p style="padding-left: 30px;"><span style="color: #000000;">mysql -u root -p password </span></p>
<p><span style="color: #000000;">create database and table</span></p>
<p><span style="color: #000000;"> create database mydb<br />
</span></p>
<p style="padding-left: 30px;"><span style="color: #000000;">use mydb<br />
</span></p>
<p style="padding-left: 30px;"><span style="color: #000000;">create table </span><span style="font-family: courier new,monospace;">mydb.ips (</span> <span style="font-family: courier new,monospace;">rdate DATE,</span> <span style="font-family: courier new,monospace;">ip VARCHAR(20) NOT NULL PRIMARY KEY,</span> <span style="font-family: courier new,monospace;">owner VARCHAR(25)</span><span style="font-family: courier new,monospace;">);</span></p>
<p style="padding-left: 30px;"><span style="font-family: courier new,monospace;">exit</span></p>
<p>Suppose the IP of the box where you are running the cgi is &#8220;172.22.22.188&#8243; (your local ip).</p>
<p>Now construct the urls for your colleagues this way:</p>
<p><a href="http://172.22.22.188/cgi-bin/retrip.sh?owner=alexm" target="_blank">http://172.22.22.188/cgi-bin/getip.sh?owner=alexm</a><br />
<a href="http://172.22.22.188/cgi-bin/retrip.sh?owner=nsarma" target="_blank">http://172.22.22.188/cgi-bin/getip.sh?owner=nsarma</a><br />
&#8230;<br />
&#8230;</p>
<p>And send them the individual urls in mail with a request to click the url (just to help you collecting the ips in the mysql table)</p>
<p>Once they click, your database table will be automatically populated with datas like this:</p>
<p>mysql&gt; select * from mydb.ips;<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<div id=":2xf" class="ArwC7c ckChnd">&#8212;&#8212;&#8212;+<br />
| rdate | ip | owner |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br />
| 2007-01-02 | 172.22.22.111 | alexm |<br />
| 2007-01-03 | 172.22.22.92 | nsarma |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br />
2 rows in set (0.00 sec)</div>
<div class="ArwC7c ckChnd">Finished.</div>
<p><span style="font-family: courier new,monospace;"><br />
</span></p>
<p><span style="font-family: courier new,monospace;"><br />
</span></p>
<p><span style="color: #000000;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://linuxbuddies.com/2009/01/03/collecting-user-ip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
