Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created January 11, 2011 13:44
Show Gist options
  • Save chmouel/774421 to your computer and use it in GitHub Desktop.
Save chmouel/774421 to your computer and use it in GitHub Desktop.
Guess file magic without using python-magic
#!/usr/bin/python
# -*- encoding: utf-8 -*-
__author__ = "Chmouel Boudjnah <[email protected]>"
binhexjpg="ffd8ffe000104a464946"
import sys
import binascii
if len(sys.argv) >= 2:
ff = sys.argv[1]
else:
print "Arg needed"
sys.exit(1)
fh = open(ff, "rb")
f = fh.read(10)
print binascii.hexlify(f)
print binhexjpg
print binascii.hexlify(f) == binhexjpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment