This is exactly what glibc's res_query() and getaddrinfo() do internally against a resolver like 8.8.8.8 or 1.1.1.1, encoding names into DNS's length-prefixed label format before parsing the answer section. Dan Kaminsky's 2008 cache-poisoning attack exploited weak randomization in the very transaction ID field you set here, which is why modern resolvers randomize both the ID and the source port.