Skip to content

Instantly share code, notes, and snippets.

@iptoux
Last active April 21, 2023 21:47
Show Gist options
  • Save iptoux/5aff794d6ebc661d13760dc57ba976ea to your computer and use it in GitHub Desktop.
Save iptoux/5aff794d6ebc661d13760dc57ba976ea to your computer and use it in GitHub Desktop.
Ip to binary converter
#!/usr/bin/env python3
import cbin.py
# Convert function
def ipTobin(ip):
# Split the ip adress
ip = ip.split('.')
# Set variable to hold binary output
b = ''
# Set dot counter
d = 0
# The convert loop
for n in ip:
b += str(cbin(int(n)))
d = d + 1
if(d <= 3):
b += '.'
# Returning value
return b
@iptoux
Copy link
Author

iptoux commented Apr 21, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment