Renaming the materials with same maps to have the same name

Actually I would like to have a script that fuse the materials with same maps and become one instance, but since there is only a script that fuse materials with the same name, so is it possible to make a script that renames the materials with same maps to have the same name?

Like mat11 uses rso_obj_roadA.png(Diffuse) and mat17 also use rso_obj_roadA.png(Diffuse)
Then rename the random one to mat11, then I can use the other script to fuse them.

I'm very new to Maxscript, I will try to learn it later, but this script is quite urgent....

Anyone who can help me I appreciate it a lot, thanks!