With MySQL < 5.6.3, you can do this with a combination of SUBSTR() and ORD():
SELECT INET_NTOA(
ORD(SUBSTR(' !"#', 1, 1)) * 16777216 +
ORD(SUBSTR(' !"#', 2, 1)) * 65536 +
ORD(SUBSTR(' !"#', 3, 1)) * 256 +
ORD(SUBSTR(' !"#', 4, 1)))
Which results in:
32.33.34.35
Also, since you're practically there already, you could just create the string yourself with CONCAT():
SELECT CONCAT(
ORD(SUBSTR(' !"#', 1, 1)), '.',
ORD(SUBSTR(' !"#', 2, 1)), '.',
ORD(SUBSTR(' !"#', 3, 1)), '.',
ORD(SUBSTR(' !"#', 4, 1)))
I hope you're using VARCHAR (as opposed to CHAR) with MySQL 5+ or a binary column so you don't lose your trailing spaces.
To support IPv6, you'll need to check the length first with an IF statement and concatenate a little differently.
With MySQL 5.6.3, the new INET6_NTOA() function supports this directly. It takes in a binary string and supports both IPv4 and IPv6:
SELECT INET6_NTOA(' !"#')
how do I read a string like !"#?