Skip to content

Instantly share code, notes, and snippets.

@secondfry
Last active October 29, 2019 16:00
Show Gist options
  • Save secondfry/0afb3f885e013005bb64e5de0a3cf68e to your computer and use it in GitHub Desktop.
Save secondfry/0afb3f885e013005bb64e5de0a3cf68e to your computer and use it in GitHub Desktop.
Identify all IP adresses which are part of the same subnet #ecole42 #school21 #init
#!/bin/sh
# (c) Copyright 2019 oadhesiv
# MIT license
# rgbg vavg hxenqra f tvgn, fzryb fgni zvahf fbebx qin
ping -c 2 -b $(ip -o -4 addr show dev en0 | awk '{print $6}')
arp -i en0 -n | grep . | awk '{print $1}'
#!/bin/sh
# (c) Copyright 2019 oadhesiv
# MIT license
# rgbg vavg hxenqra f tvgn, fzryb fgni zvahf fbebx qin
nmap -sL -n $(ip -o -4 addr show dev en0 | awk '{print $4}') | grep 'Nmap scan report for' | cut -f 5 -d ' '
#!/usr/bin/python3
# (c) Copyright 2019 oadhesiv
# MIT license
# rgbg vavg hxenqra f tvgn, fzryb fgni zvahf fbebx qin
import ipaddress
import os
# You should be on modern system with iproute2
# ipint_str = os.system('ip -o -4 addr show dev en0 | awk \'{print $4}\'')
# This is deprecated
ip = os.system('ifconfig en0 | grep "inet " | awk \'{print $2}\'')
netmask_hex = os.system('ifconfig en0 | grep "inet " | awk \'{print $4}\'')
netmask = bin(int(netmask_hex, 0)).count('1')
ipint_str = '{}/{}'.format(ip, netmask)
ipint = ipaddress.IPv4Interface(ipint)
net = ipint.network
for ip in net.hosts():
print(ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment