LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2019, 03:27 PM   #1
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Rep: Reputation: 57
How to simulate a DNS client with socat


Using socat, how do you send data to a public DNS server through UDP and receive the reply into a file or pipe?

The following only sends the data (data is in proper DNS binary format in a file called "query.bin", previously intercepted from dig transmissions):

socat GOPEN:query.bin udp-send:8.8.8.8:53

The following only receives the data:

socat GOPEN:received.bin,append udp-listen:10.0.0.13:53

Except port 53 is wrong in the latter. How do you both send and receive? Must TCP be used instead? If so, how?

Last edited by Ulysses_; 05-22-2019 at 03:54 AM.
 
Old 05-23-2019, 09:33 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
I would try dual-address form for the first argument.

Code:
socat 'GOPEN:query.bin||CREATE:result.bin' udp-send:8.8.8.8:53

Edit: I don't think this will work. socat always shuts down when it hits EOF on the input side, so it won't wait for the response. Maybe you can pipe the data to it somehow and leave the input side open,

Last edited by smallpond; 05-23-2019 at 09:41 AM.
 
Old 05-24-2019, 03:43 AM   #3
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
Doesn't work, it produces this error:

socat[119273] E GOPEN: wrong number of parameters (3 instead of 1)

Tried this too:

socat -x system:"cat query.bin; tr a a > result.bin" udp-send:8.8.8.8:53
> 2019/05/24 12:44:09.736162 length=50 from=0 to=49
c5 42 01 20 00 01 00 00 00 00 00 01 05 68 65 6c 6c 6f 03 63 6f 6d 00 00 01 00 01 00 00 29 10 00 00 00 00 00 00 0c 00 0a 00 08 91 86 b5 9f e1 9f d4 b3
< 2019/05/24 12:44:09.805138 length=102 from=0 to=101
c5 42 81 80 00 01 00 04 00 00 00 01 05 68 65 6c 6c 6f 03 63 6f 6d 00 00 01 00 01 c0 0c 00 01 00 01 00 00 1a 28 00 04 d8 ef 26 15 c0 0c 00 01 00 01 00 00 1a 28 00 04 d8 ef 20 15 c0 0c 00 01 00 01 00 00 1a 28 00 04 d8 ef 22 15 c0 0c 00 01 00 01 00 00 1a 28 00 04 d8 ef 24 15 00 00 29 02 00 00 00 00 00 00 00

It does send the query, it does receive the result, but how do you store the result in result.bin?

Here's how query.bin was generated. In one terminal:

socat udp-l:53,reuseaddr,fork system:"tee query.bin"

and in another terminal:

dig +notcp hello.com @127.0.0.1
 
Old 05-24-2019, 04:12 AM   #4
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
What would be the iptables rules to send everything that comes from 8.8.8.8 to port 1111 so the following can catch it?

socat -x udp-l:1111,reuseaddr,fork system:"tee result.bin"
 
Old 05-24-2019, 04:28 AM   #5
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
It's extremely simple in the end:

cat query.bin | socat -x - UDP:8.8.8.8:53 > result.bin
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is possible to simulate Load balancing algorithms using NS-2?for example i am trying to simulate Least Connection algorithm. mariio Linux - Networking 3 05-05-2016 08:06 AM
netcat or socat expert needed wgcampbell Linux - Networking 5 03-01-2010 12:39 PM
socat slow Lorian Linux - Networking 0 05-11-2009 10:30 AM
Debian for mips: installing socat (and related problems) SomeIdiot Linux - Software 3 03-25-2009 01:17 PM
LXer: CLI Magic: socat LXer Syndicated Linux News 0 03-26-2007 08:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration