syntax off set number set columns=120 set ruler
Wednesday, May 2, 2012
Friday, April 13, 2012
Basic ssh login script
#!/usr/bin/env bash ip="127.0.0.1"; u="joe"; p="2222" webport="8080"; while true; do echo "http://$ip:$webport": echo "ssh -p $p $u@$ip"; read -p "press enter"; ssh -p $p $u@$ip; done
Tuesday, March 20, 2012
Create an associative array in PHP
Some of you may dislike the distraction of a full set of working code with core lesson of associative arrays buried in it. Their are plenty of minimalist examples on the web, and when I wanted an example they were too minimalist. Core code for reference is in this color scheme.
deviceNickNames.txt10.AF2551010800|no nickname 22.20F21A000000|no nickname 22.650E1B000000|no nickname 29.A29F09000000|no nickname
$deviceNickNamesTxt = "deviceNickNames.txt";
if (file_exists($deviceNickNamesTxt)) {
$lines=explode("\n", file_get_contents($deviceNickNamesTxt));
foreach($lines as $line) {
$items=explode("|",$line);
if(isset($items[1])) { $devicesB[$items[0]]= $items[1]; }
}
}
print "\n<form name=\"setupForm\" action=\"\" method=\"GET\">\n<table>\n<tr><th>Device Hardcoded Name</th><th>Human Friendly Name</th></tr>\n";
foreach($devicesB as $name => $value) {
print "\n<tr>";
print "\n<td valign=\"center\" align=\"center\">".$name."</td>";
print "\n<td valign=\"center\" align=\"center\">\n";
inputText($name."_NAME", $value, "");
submit("");
print "</td>\n</tr>\n";
}
print "\n</table>\n</form>\n"
| Device Hardcoded Name | Human Friendly Name |
|---|---|
| 10.AF2551010800 | |
| 22.20F21A000000 | |
| 22.650E1B000000 | |
| 29.A29F09000000 |
Friday, March 9, 2012
Boiler plate ajax.php file
Hello, I am /ajax.php
To make me work properly please send GET or POST data
I am designed to not need editing, all the things you want to add to my functionality
should be written in a file called /home/cyr/public_html/inc/ajax.txt
Also, I am intelligent enough to see there is no /home/cyr/public_html/inc/ajax.txt
I leave it up to you to create that.
Below is /home/cyr/public_html/ajax.php source code
===============================
<?php
if(isset($_GET['test'])) { error_reporting(E_ALL);ini_set('display_errors', '1'); }
if(isset($_POST['test'])) { error_reporting(E_ALL);ini_set('display_errors', '1'); }
header("Content-Type: text/plain");
$page=getenv("SCRIPT_NAME");
$query=getenv("QUERY_STRING");
$referer=getenv("HTTP_REFERER");
$ip=getenv("REMOTE_ADDR");
$docRoot=getenv('DOCUMENT_ROOT');
if(isset($_GET['test'])) { foreach($_GET as $name => $value) { print "\n".$name." : ".$value; } die();}
if(isset($_POST['test'])) { foreach($_POST as $name => $value) { print "\n".$name." : ".$value; } die();}
$includesDir="inc";
$includesDir=getcwd()."/".$includesDir;
$file=$includesDir."/".basename($page,"php")."txt";
if((count($_GET) < 1) && (count($_POST) < 1)) {
print "Hello, I am ".$page."\n";
print "To make me work properly please send GET or POST data\n";
print "I am designed to not need editing, all the things you want to add to my functionality\n";
print "should be written in a file called ".$file."\n";
if(!is_dir($includesDir)) { print "Also, I see there is no ".$includesDir."\nPlease create this directory and place a file named '".basename($page,"php")."txt' in it";}
elseif(!is_file($file)) { print "Also, I am intelligent enough to see there is no ".$file."\nI leave it up to you to create that.\n"; }
print "Below is ".$_SERVER['SCRIPT_FILENAME']." source code\n===============================\n";
print file_get_contents($_SERVER['SCRIPT_FILENAME']);
print "\n";
if (is_file($file)) {
print "Below is ".$file." source code\n===============================\n";
print file_get_contents($file);
}
die();
}
is_file($file) ? include($file) : print $file." does not exist";
die();
?>
Wednesday, February 29, 2012
netdiscover
Not saying anything smart in this post, just placing here as note to self about the name of this tool and basic commands to get it started if I'm on a new machine that needs it.
sudo apt-get install netdiscover sudo netdiscover sudo netdiscover -r 192.168.1.0/24 sudo netdiscover -i wlan0 -r 192.168.1.0/24 sudo netdiscover -h Netdiscover 0.3-beta7 [Active/passive arp reconnaissance tool] Written by: Jaime PenalbaUsage: netdiscover [-i device] [-r range | -l file | -p] [-s time] [-n node] [-c count] [-f] [-d] [-S] [-P] [-C] -i device: your network device -r range: scan a given range instead of auto scan. 192.168.6.0/24,/16,/8 -l file: scan the list of ranges contained into the given file -p passive mode: do not send anything, only sniff -F filter: Customize pcap filter expression (default: "arp") -s time: time to sleep between each arp request (miliseconds) -n node: last ip octet used for scanning (from 2 to 253) -c count: number of times to send each arp reques (for nets with packet loss) -f enable fastmode scan, saves a lot of time, recommended for auto -d ignore home config files for autoscan and fast mode -S enable sleep time supression betwen each request (hardcore mode) -P print results in a format suitable for parsing by another program -L in parsable output mode (-P), continue listening after the active scan is completed If -r, -l or -p are not enabled, netdiscover will scan for common lan addresses.
Labels:
lan,
linux,
netdiscover,
network,
networking,
ubuntu
Thursday, January 19, 2012
Print just the name of the running Python program
#!/usr/bin/env python
import sys
import os
for i in sys.argv:
print i
print sys.argv[0]
print os.path.basename(sys.argv[0].split(".")[0])
#>bin/test.py 56 555 bin/test.py 56 555 bin/test.py test
Sunday, January 1, 2012
MySQL Connect in Python
#!/usr/bin/env python
import pymysql
conn = pymysql.connect(host='localhost', user='root', passwd='cyrushellborg666', db='brewing')
cur = conn.cursor()
cur.execute("SHOW TABLES")
# print cur.description
# r = cur.fetchall()
# print r
# ...or...
for r in cur:
print r
cur.close()
conn.close()
Subscribe to:
Posts (Atom)