From 318b3220d191011bb9132efd4dbd5e6fb467b4e7 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Tue, 21 Apr 2015 13:41:40 -0500 Subject: made dcchelper a script instead of a c program. ipdist which gives shortest distance based on whob's output of lat and lon nc.* are minmal versions of a netcat like program written in Perl. rfc is a script for downloading and viewing RFCs tpb.sh is for pulling magnet links from tpb search results. cuturl got an upgrade to better handle scheme:?query_string type URLs. (URN? URI? fuck if I know.) --- nocompile/bin/dcchelper | 10 ++++++++++ nocompile/bin/ipdist.sh | 26 ++++++++++++++++++++++++++ nocompile/bin/nc.perl1.sh | 2 ++ nocompile/bin/nc.pl | 3 +++ nocompile/bin/rfc | 8 ++++++++ nocompile/bin/tpb.sh | 36 ++++++++++++++++++++++++++++++++++++ src/bin/cuturl.c | 38 +++++++++++++++++++++++++++----------- 7 files changed, 112 insertions(+), 11 deletions(-) create mode 100755 nocompile/bin/dcchelper create mode 100755 nocompile/bin/ipdist.sh create mode 100755 nocompile/bin/nc.perl1.sh create mode 100755 nocompile/bin/nc.pl create mode 100755 nocompile/bin/rfc create mode 100755 nocompile/bin/tpb.sh diff --git a/nocompile/bin/dcchelper b/nocompile/bin/dcchelper new file mode 100755 index 0000000..d4f3fc9 --- /dev/null +++ b/nocompile/bin/dcchelper @@ -0,0 +1,10 @@ +#!/bin/sh +hop0="$(hop0 "$1")" +if [ "$hop0" = "192.168.0.2" ];then + if ! printf "%s" "$1" | grep "^192\.168\.0\." 2>&1 >/dev/null;then + IP=$(dig +short armitage.hacking.allowed.org @8.8.8.8) + fi +else + IP=$hop0 +fi +ipconvert "$IP" | grep "^dec: " | cut '-d ' -f2 diff --git a/nocompile/bin/ipdist.sh b/nocompile/bin/ipdist.sh new file mode 100755 index 0000000..ca97696 --- /dev/null +++ b/nocompile/bin/ipdist.sh @@ -0,0 +1,26 @@ +#!/bin/sh +if [ "_$1" = "_" -o "_$2" = "_" ];then + echo "usage: $0 hostA hostB" + exit +fi + +#constants for now. +c=299.792458 #km/ms of light in vacuum +iof=1.4475 #picked the higher of two from wikipedia. +# http://en.wikipedia.org/wiki/Optical_fiber#Index_of_refraction + +ipA=$(gethostbyname "$1") +ipB=$(gethostbyname "$2") +A=$(whob "$ipA" | egrep "^Lat|^Lon" | cut '-d ' -f2 | tr '\n' ' ') +B=$(whob "$ipB" | egrep "^Lat|^Lon" | cut '-d ' -f2 | tr '\n' ' ') +km=$(echo "$A" "$B" \ + | geod +ellps=clrk66 -I +units=km \ + | cut -f3) +ms=$(printf '%s / %s * %s\n' "$km" "$c" "$iof" | bc) + +echo "ipA: $ipA" +echo "ipB: $ipB" +echo "c: $c" +echo "iof: $iof" +echo "km: $km" +echo "ms: $ms" diff --git a/nocompile/bin/nc.perl1.sh b/nocompile/bin/nc.perl1.sh new file mode 100755 index 0000000..cfd8535 --- /dev/null +++ b/nocompile/bin/nc.perl1.sh @@ -0,0 +1,2 @@ +#!/bin/sh +perl -mIO::Socket -e '$socket=IO::Socket::INET->new(PeerAddr=>"$ARGV[0]:$ARGV[1]",Proto=>"tcp",Timeout=>1);if(fork()) {while($l=) {print $socket "$l";}} else {while($l=<$socket>) {print $l;}}' $1 $2 diff --git a/nocompile/bin/nc.pl b/nocompile/bin/nc.pl new file mode 100755 index 0000000..ff52ab7 --- /dev/null +++ b/nocompile/bin/nc.pl @@ -0,0 +1,3 @@ +#!/usr/pkg/bin/perl +use IO::Socket; +$s=IO::Socket::INET->new(PeerAddr=>"$ARGV[0]:$ARGV[1]",Proto=>"tcp",Timeout=>1);if(fork()){while($l=){print $s $l;}}else{while($l=<$s>){print $l;}} diff --git a/nocompile/bin/rfc b/nocompile/bin/rfc new file mode 100755 index 0000000..56440ae --- /dev/null +++ b/nocompile/bin/rfc @@ -0,0 +1,8 @@ +#!/bin/sh +RFCPATH=/anarchy/rfc +if [ ! -f "${RFCPATH}/rfc$1.txt" ];then + echo "RFC file not found... downloading..." + wget http://www.ietf.org/rfc/rfc$1.txt -O "${RFCPATH}/rfc$1.txt" + echo "RFC has now been downloaded." +fi +less "${RFCPATH}/rfc$1.txt" diff --git a/nocompile/bin/tpb.sh b/nocompile/bin/tpb.sh new file mode 100755 index 0000000..7162b21 --- /dev/null +++ b/nocompile/bin/tpb.sh @@ -0,0 +1,36 @@ +#!/bin/sh +#get magnets based on search. easy. :P +if [ "_$1" = "_" ];then + echo usage: tpb.sh search_term [category] [limit] + echo "categories:" + echo "0 = any" + echo "100 = audio" + echo "200 = video" + echo "300 = applications" + echo "400 = games" + echo "500 = porn" + +else + if [ "_$2" = "_" ];then + cat=0 + else + cat="$2" + fi + if [ "_$3" = "_" ];then + lim=5 + else + lim="$3" + fi +#last number: +#0 = any +#100 = audio +#200 = video +#300 = applications +#400 = games +#500 = porn + wget -qO- 'https://thepiratebay.se/search/'"$1"'/0/99/'"$cat" \ + | tr '"' "\n" \ + | grep ^magnet \ + | decode_html_entities \ + | head -n "$lim" +fi diff --git a/src/bin/cuturl.c b/src/bin/cuturl.c index f8b02c7..d706fd3 100644 --- a/src/bin/cuturl.c +++ b/src/bin/cuturl.c @@ -175,17 +175,25 @@ int main(int argc,char *argv[]) { } if(domain) { - if(strchr(domain,']')) { + if(strchr(domain,']')) {//the end of an IPv6 address if(strchr(strchr(domain,']'),':')) { port=strchr(strchr(domain,']'),':'); - *port=0; - port++; + if(port[1] == '?') {//for magnet links + port=0; + } else { + *port=0; + port++; + } } } else { if(strchr(domain,':')) { port=strchr(domain,':'); - *port=0; - port++; + if(port[1] == '?') {//for magnet links + port=0; + } else { + *port=0; + port++; + } } } } @@ -198,23 +206,31 @@ int main(int argc,char *argv[]) { } } - if(!scheme && username) { + if(strchr(domain,':') && !strchr(domain,']')) {//for scheme:?query_string + scheme=domain; + *strchr(scheme,':')=0; + domain=0; + } + + if(!scheme && username) {//for mailto: scheme=username; username=password; password=0; } - if(!domain) { - fprintf(stderr,"how the fuck is this supposed to be a URL?\n"); - return 1; - } +// before deciding to also handle magnets +// if(!domain) { +// fprintf(stderr,"how the fuck is this supposed to be a URL?\n"); +// return 1; +// } + // printf("scheme://username:password@domain:port/path?query_string#fragment_id\n\n"); //let's set them to what'll get printed now... scheme=AorB(scheme,AorB(getenv("CUTURL_SCHEME"),"DEFAULT")); username=AorB(username,AorB(getenv("CUTURL_USERNAME"),"DEFAULT")); password=AorB(password,AorB(getenv("CUTURL_PASSWORD"),"DEFAULT")); - //domain=domain; doesn't change. heh. + domain=AorB(domain,AorB(getenv("CURURL_DOMAIN"),"DEFAULT")); serv=getservbyname(scheme,strcmp(scheme,"udp")?"tcp":"udp"); if(serv) snprintf(sport,sizeof(sport)-1,"%d",ntohs(serv->s_port)); port=AorB(port,AorB(getenv("CUTURL_PORT"),(serv?sport:"DEFAULT"))); -- cgit v1.2.3