Take a drill and 3/8″ bit and drill out lead all around the pipe. You can caulk a new one on the pipe are the box store is got one with a rubber washer and bolted flange wher you can set it over pipe and tighten the bolts and then screw it down to the floor, it has a good heffty price on it, set the flange bolt holes on the same center as the pipe, measure off the wall, go to search and ask them how to istall a Toilet closet flange.