import socket,struct,sys
HOST='10.0.0.17'
def rpc_call(port,prog,vers,proc,args=b'',timeout=6):
    s=socket.create_connection((HOST,port),timeout=timeout)
    xid=0x12345678
    call=struct.pack('>IIIIII',xid,0,2,prog,vers,proc)
    call+=struct.pack('>II',0,0)  # cred AUTH_NULL
    call+=struct.pack('>II',0,0)  # verf AUTH_NULL
    call+=args
    rec=struct.pack('>I',0x80000000|len(call))+call
    s.sendall(rec)
    hdr=s.recv(4)
    if len(hdr)<4: return None
    ln=struct.unpack('>I',hdr)[0]&0x7fffffff
    data=b''
    while len(data)<ln:
        chunk=s.recv(ln-len(data))
        if not chunk: break
        data+=chunk
    s.close()
    return data
def parse_reply(data):
    if not data or len(data)<24: return None
    xid,msgtype,replystat=data[0:4],data[4:8],data[8:12]
    off=12
    # verf
    flavor,ln=struct.unpack('>II',data[off:off+8]); off+=8+((ln+3)//4*4)
    accept=struct.unpack('>I',data[off:off+4])[0]; off+=4
    return accept,data[off:]
def export_list():
    r=rpc_call(111,100000,2,3,struct.pack('>IIII',100005,3,6,0))
    print('GETPORT_RAW',r.hex() if r else None)
    if not r: return []
    acc,res=parse_reply(r)
    print('GETPORT accept',acc,'res',res.hex() if res else None)
    if acc!=0 or not res: return []
    port=struct.unpack('>I',res[:4])[0]
    print('MOUNTD_PORT',port)
    r2=rpc_call(port,100005,3,5,b'')
    print('EXPORT_RAW_LEN',len(r2) if r2 else None)
    if not r2: return []
    acc2,res2=parse_reply(r2)
    print('EXPORT accept',acc2)
    out=[]; off=0
    while True:
        if off+4>len(res2): break
        more=struct.unpack('>I',res2[off:off+4])[0]; off+=4
        if more==0: break
        ln=struct.unpack('>I',res2[off:off+4])[0]; off+=4
        path=res2[off:off+ln].decode('utf-8','replace'); off+= (ln+3)//4*4
        out.append(path)
    return out
print('EXPORTS',export_list())
