Last active
April 21, 2023 21:47
-
-
Save iptoux/5aff794d6ebc661d13760dc57ba976ea to your computer and use it in GitHub Desktop.
Ip to binary converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need cbin.py
https://gist.github.com/iptoux/1592d5b469173b7d4659b6008570fb82