Skip to content

Instantly share code, notes, and snippets.

@gerjantd
gerjantd / gist:10349414
Created April 10, 2014 06:55
Bash/rename: rename multiple files
http://stackoverflow.com/questions/1392768/rename-part-of-filename
rename 's/201402/201404/' 201402*
@gerjantd
gerjantd / gist:9787606
Created March 26, 2014 16:40
Bash/nc: netcat as a simple port scanner
PORT SCANNING
It may be useful to know which ports are open and running services on a target machine. The -z flag can be used to tell nc to report open ports, rather than initiate a connection. Usually it's useful to turn on verbose output to stderr by use this
option in conjunction with -v option.
For example:
$ nc -zv host.example.com 20-30
Connection to host.example.com 22 port [tcp/ssh] succeeded!
Connection to host.example.com 25 port [tcp/smtp] succeeded!
@gerjantd
gerjantd / gist:9787569
Created March 26, 2014 16:38
Bash/nc: netcat as a simple http/smtp client
TALKING TO SERVERS
It is sometimes useful to talk to servers “by hand” rather than through a user interface. It can aid in troubleshooting, when it might be necessary to verify what data a server is sending in response to commands issued by the client. For example, to
retrieve the home page of a web site:
$ printf "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
Note that this also displays the headers sent by the web server. They can be filtered, using a tool such as sed(1), if necessary.
More complicated examples can be built up when the user knows the format of requests required by the server. As another example, an email may be submitted to an SMTP server using:
@gerjantd
gerjantd / gist:9787538
Created March 26, 2014 16:36
Bash/nc: netcat as a simple ftp server
DATA TRANSFER
The example in the previous section can be expanded to build a basic data transfer model. Any information input into one end of the connection will be output to the other end, and input and output can be easily captured in order to emulate file trans‐
fer.
Start by using nc to listen on a specific port, with output captured into a file:
$ nc -l 1234 > filename.out
Using a second machine, connect to the listening nc process, feeding it the file which is to be transferred:
@gerjantd
gerjantd / gist:9787489
Last active January 9, 2024 14:25
Bash/nc: netcat as a simple telnet server
CLIENT/SERVER MODEL
It is quite simple to build a very basic client/server model using nc. On one console, start nc listening on a specific port for a connection. For example:
$ nc -l 1234
nc is now listening on port 1234 for a connection. On a second console (or a second machine), connect to the machine and port being listened on:
$ nc 127.0.0.1 1234
There should now be a connection between the ports. Anything typed at the second console will be concatenated to the first, and vice-versa. After the connection has been set up, nc does not really care which side is being used as a ‘server’ and which
@gerjantd
gerjantd / gist:9706483
Last active August 29, 2015 13:57
Commands to restart unity without losing session
Ctrl+Alt+F1, log on
unity &> /dev/null & disown
or (unity is a compiz plugin)
compiz --replace &> /dev/null & disown
http://askubuntu.com/questions/38579/how-do-i-restart-an-unity-session-from-the-terminal
@gerjantd
gerjantd / gist:9158091
Last active August 29, 2015 13:56
Bash/Perl script to replace spaces in file names
# http://stackoverflow.com/questions/2709458/bash-script-to-replace-spaces-in-file-names
find ./tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
@gerjantd
gerjantd / list-objects.jsp
Created January 31, 2014 10:09
List JSP implicit object
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@gerjantd
gerjantd / gist:8706765
Created January 30, 2014 11:33
Tail remote log, save new lines locally and prettify json embedded in log lines using swatch and python
ssh user@host tail -F /usr/share/tomcat/logs/catalina.out >> /tmp/host-catalina.out
vi ~/.swatchrc:
watchfor /"from"/
pipe 'cut -f5- -d" "|python -mjson.tool'
swatch -c ~/.swatchrc -t /tmp/host-catalina.out
@gerjantd
gerjantd / scrape.groovy
Created April 24, 2013 16:57
Groovy: scrape mp3 links in html and download all
@Grab(group='net.sourceforge.nekohtml', module='nekohtml', version='1.9.18')
import org.cyberneko.html.parsers.SAXParser
def download(address)
{
def file = new FileOutputStream(address.tokenize("/")[-1])
def out = new BufferedOutputStream(file)
out << new URL(address).openStream()
out.close()
}