Posts

Showing posts from October, 2012

Perl Net::SSH2::SFTP Example

In my experiences, code has sometimes been better at explaining than documentation. Why did I do this? Because I didn't find it immediately when I searched for it... Cheers! Copy From PasteBin! #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::SSH2; use Net::SFTP; use Carp; use Fcntl; use Fcntl ':DEFAULT'; use constant SSH_USER => 'root'; use constant SSH_PASS => 'toor'; use constant SSH_HOST => 'localhost'; use constant SSH_PORT => 21; my ( $conn, $ssh, $sftp, $buf, $buffer, $len ); sub ssh_connect { my ( $ssh, $user, $host, $pass, $port ); ( $user, $pass, $host, $port ) = @_; $host ||= 'localhost'; $port ||= 22; $ssh = new Net::SSH2; $ssh->debug(1); $ssh->blocking(1); return 0 unless $ssh->connect($host . ':' . $port); print "[*] Connect OK!\n"; return 0 unless $ssh->auth( username => $user, password => $pass); print "[*] Auth OK!\n"; return $ssh; } sub...

Get Address of a Network Interface in C

So, here I am searching the internet over and over again to find out how to easily and quickly get the ip address of a local interface, and there isn't an easy way to do it without running `ifconfig | grep | cut...` in some crazy fashion. So, here I've compiled a simple C script that will iterate through your interfaces and get the IP address of a local network interface if you supply it on the command line. Feel free to redistribute under GNU. https://github.com/markizano/scripts/blob/master/getifaddr/getifaddr.c /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Gene...