Getting Color Index from Pixel

I’m trying to create a script that will export the color indexes of every pixel to a file. I’m struggling to get the index value of a pixel. My image’s color mode is set to Indexed.