Skip to content

Instantly share code, notes, and snippets.

View kapil1024's full-sized avatar

Kapil kapil1024

View GitHub Profile
@kapil1024
kapil1024 / RedfishValdator.md
Last active January 19, 2022 12:57
How to use Redfish Service Validator

Basic steps:

Install python3 and pip3

sudo apt update -y
sudo apt install python3 python3-pip git unzip -y

Clone the repo

@kapil1024
kapil1024 / netcat_port_forwarding.md
Created December 18, 2021 11:56
Port forwarding using netcat (nc)

Network setup

10.1.1.4/24 --> a system connected to bmc system. 10.1.1.5/24 --> bmc system. localhost --> my laptop. Suppose we want to access a service running at UDP port 623 but UDP port 623 is blocked by our firewall and TCP port 80 is unblocked. So we can use nc to create a tunnel using TCP port 80.

Configuration

  1. laptop terminal#1:
    • mkfifo /tmp/fifo
    • sudo nc -l -u -p 623 < /tmp/fifo | nc 10.1.1.4 80 > /tmp/fifo
@kapil1024
kapil1024 / hexdump.js
Last active December 18, 2021 12:18
Hexdump in javascript
// Modified version of https://gist.github.com/igorgatis/d294fe714a4f523ac3a3
function hexdump(buffer, blockSize, maxLength) {
if(typeof buffer === 'string'){
console.log("buffer is string");
//do nothing
}else if(buffer instanceof ArrayBuffer && buffer.byteLength !== undefined){
console.log("buffer is ArrayBuffer");
var tlen = buffer.byteLength;
if (tlen > 65000) tlen = 65000;
buffer = String.fromCharCode.apply(String, [].slice.call(new Uint8Array(buffer, 0, tlen)));
@kapil1024
kapil1024 / websockify_c.md
Created December 18, 2021 08:39
Using websockify (C language) as a websocket to TCP bridge

Project URL https://github.com/novnc/websockify-other

Building websockify

  • apt install openssl-dev
  • git clone git@github.com:novnc/websockify-other.git websockify
  • cd websockify/c
  • make
  • cp websockify /usr/bin
@kapil1024
kapil1024 / file_servers.md
Last active January 18, 2022 11:55
Setting up nbd server, https server, samba server and tftp server on ubuntu 18.04

Install required packages

apt install -y nbd-server nbd-client apache2 wget samba smbclient cifs-utils tftpd-hpa tftp

Set a variable for local IP (not mandatory)

export LOCAL_IP="192.168.21.2"

HTTPS server

  1. Enable SSL module and restart the server
    • a2enmod ssl
  • a2ensite default-ssl
@kapil1024
kapil1024 / enable_swap.md
Created December 17, 2021 17:35
Enable swap space to virtually expand the RAM
  1. Check current state of swap swapon -s

  2. Turn off the swap swapoff -a

  3. Formate a file or block device as swap mkswap /dev/sdX

  4. Update fstab to mount this swap devie/file on every boot

@kapil1024
kapil1024 / testpam.c
Created September 21, 2021 18:14
Using Linux PAM to authenticate
/*
* This program is inspired from following articles -
* http://www.linux-pam.org/Linux-PAM-html/adg-example.html
* https://docs.oracle.com/cd/E23824_01/html/819-2145/pam-1.html#pam-20
* https://man7.org/tlpi/code/online/book/tty/no_echo.c.html
*
* Install required packages:
* $ sudo apt-get install libpam-dev -y
*
* Compile using gcc:
@kapil1024
kapil1024 / dbus_client.c
Created June 12, 2021 07:13
sdbus library: Dbus client-server application over user/system bus
#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
int main(int argc, char *argv[]) {
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *m = NULL;
sd_bus *bus = NULL;
int64_t x, y, z;
int r;
@kapil1024
kapil1024 / dbus_socket_app.c
Created June 12, 2021 06:32
sdbus library: dbus client-server using socket pair
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <systemd/sd-bus.h>
int fds[2];
#define INT_TO_PTR(integer) ((void*) (long) ((int)integer))
@kapil1024
kapil1024 / sudoku_solver.c
Last active March 21, 2021 06:42
C code to solve any Sudoku puzzle
#include<stdio.h>
// A sample puzzle
int sudoku[9][9] = { {0,0,0,4,0,0,0,9,0},
{0,3,0,0,5,0,0,1,8},
{0,0,0,0,0,0,6,0,7},
{4,2,0,1,0,3,0,0,6},
{0,9,0,0,0,0,0,2,0},
{7,0,0,2,0,8,0,4,1},
{6,0,4,0,0,0,0,0,0},